From 116206c95ecccf49fcce426b0f353d84a17b3314 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 31 Jan 2022 23:15:34 +0000 Subject: Add the key operator --- apl9.h | 1 + operators.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/apl9.h b/apl9.h index cad5ae4..e33df18 100644 --- a/apl9.h +++ b/apl9.h @@ -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, /* ⌾ */ @@ -79,6 +79,17 @@ opSwitch(Datum *lefto, Array *left, Array *right) return nil; } +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) { -- cgit v1.2.3