diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-31 23:15:34 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-31 23:15:34 +0000 |
commit | 116206c95ecccf49fcce426b0f353d84a17b3314 (patch) | |
tree | cac8974185fb1102d92f65fadcb3959157888e73 /operators.c | |
parent | 60cf57b059e7f4dcfd1a78851d9930d33a28fd9d (diff) |
Add the key operator
Diffstat (limited to 'operators.c')
-rw-r--r-- | operators.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/operators.c b/operators.c index 8fd9911..202667c 100644 --- a/operators.c +++ b/operators.c @@ -10,7 +10,7 @@ Rune primdyadopnames[] = L"⍣.∘⍤⍥@⍠⌺⍢⍫⍙"; opmonad monadoperatordefs[] = { opEach, /* ¨ */ opSwitch, /* ⍨ */ - 0, /* ⌸ */ + opKey, /* ⌸ */ 0, /* ⌶ */ 0, /* & */ opOuterProduct, /* ⌾ */ @@ -80,6 +80,17 @@ opSwitch(Datum *lefto, Array *left, Array *right) } Array * +opKey(Datum *lefto, Array *left, Array *right) +{ + if(lefto->tag != FunctionTag) + throwerror(nil, EType); + if(left) + return rundfn(L"↑⍵∘(⍶{⍵⍶⍺⌷⍨⊂⍸⍹≡¨⍵}⍺)¨⊂¨∪⍺", lefto, nil, left, right); + else + return rundfn(L"⍵⍶⌸⍳≢⍵", lefto, nil, left, right); +} + +Array * opOuterProduct(Datum *lefto, Array *left, Array *right) { if(left == nil) |