diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-24 22:02:25 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-24 22:02:25 +0000 |
commit | e77ed10bf640bf6c3cb6ce10943e0be6e82f5250 (patch) | |
tree | 8f3f1f071dd40fb1ae75c4d244d926bec61583c9 | |
parent | 5a5136ef9f981a603ca2e933e47cfd3a178be7cc (diff) |
Implement a limited form of ⍣
-rw-r--r-- | apl9.h | 1 | ||||
-rw-r--r-- | operators.c | 12 |
2 files changed, 12 insertions, 1 deletions
@@ -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, /* ⍤ */ @@ -90,6 +90,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) { if(lefto->tag == FunctionTag && righto->tag == FunctionTag){ |