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 | |
parent | 60cf57b059e7f4dcfd1a78851d9930d33a28fd9d (diff) |
Add the key operator
-rw-r--r-- | apl9.h | 1 | ||||
-rw-r--r-- | operators.c | 13 |
2 files changed, 13 insertions, 1 deletions
@@ -367,6 +367,7 @@ Array *fnSelfReference2(Array *, Array *); /* Monadic operators from operators.c */ Array *opEach(Datum *, Array *, Array *); Array *opSwitch(Datum *, Array *, Array *); +Array *opKey(Datum *, Array *, Array *); Array *opOuterProduct(Datum *, Array *, Array *); Array *opSelfReference1(Datum *, Array *, Array *); 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) |