From e77ed10bf640bf6c3cb6ce10943e0be6e82f5250 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 24 Jan 2022 22:02:25 +0000 Subject: =?UTF-8?q?Implement=20a=20limited=20form=20of=20=E2=8D=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apl9.h | 1 + operators.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apl9.h b/apl9.h index cb71b2b..68d8b3e 100644 --- a/apl9.h +++ b/apl9.h @@ -329,6 +329,7 @@ Array *opSwitch(Datum *, Array *, Array *); Array *opSelfReference1(Datum *, Array *, Array *); /* Dyadic operators from operators.c */ +Array *opPower(Datum *, Datum *, Array *, Array *); Array *opBind(Datum *, Datum *, Array *, Array *); Array *opAtop(Datum *, Datum *, Array *, Array *); Array *opOver(Datum *, Datum *, Array *, Array *); diff --git a/operators.c b/operators.c index 8feda34..93f3b74 100644 --- a/operators.c +++ b/operators.c @@ -17,7 +17,7 @@ opmonad monadoperatordefs[] = { }; opdyad dyadoperatordefs[] = { - 0, /* ⍣ */ + opPower, /* ⍣ */ 0, /* . */ opBind, /* ∘ */ opAtop, /* ⍤ */ @@ -89,6 +89,16 @@ opSelfReference1(Datum *lefto, Array *left, Array *right) } /* Dyadic operators */ +Array * +opPower(Datum *lefto, Datum *righto, Array *left, Array *right) +{ + if(righto->tag != ArrayTag || righto->array->type != AtypeInt || righto->array->rank != 0 || righto->array->size != 1 || righto->array->intdata[0] < 0) + throwerror(nil, EDomain); + if(lefto->tag != FunctionTag) + throwerror(nil, EType); + return rundfn(L"⍺←⊢ ⋄ ⍹=0:⍵ ⋄ ⍺ ⍶⍙(⍹-1)⊢⍺⍶⍵", lefto, righto, left, right); +} + Array * opBind(Datum *lefto, Datum *righto, Array *left, Array *right) { -- cgit v1.2.3