diff options
-rw-r--r-- | operators.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/operators.c b/operators.c index 93f3b74..94f4f19 100644 --- a/operators.c +++ b/operators.c @@ -92,11 +92,29 @@ opSelfReference1(Datum *lefto, Array *left, Array *right) 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); + Rune *code = nil; if(lefto->tag != FunctionTag) throwerror(nil, EType); - return rundfn(L"⍺←⊢ ⋄ ⍹=0:⍵ ⋄ ⍺ ⍶⍙(⍹-1)⊢⍺⍶⍵", lefto, righto, left, right); + if(righto->tag == FunctionTag){ + if(left) + code = L"next←⍺⍶⍵ ⋄ next⍹⍵:⍵ ⋄ ⍺ ⍶⍙⍹ next"; + else + code = L"next←⍶⍵ ⋄ next⍹⍵:⍵ ⋄ ⍶⍙⍹ next"; + }else if(righto->tag == ArrayTag){ + if(righto->array->type != AtypeInt || righto->array->rank != 0 || righto->array->size != 1 || righto->array->intdata[0] < 0) + throwerror(L"right operand to ⍣", EDomain); + if(left) + code = L"⍹=0:⍵ ⋄ ⍺ ⍶⍙(⍹-1)⊢⍺⍶⍵"; + else + code = L"⍹=0:⍵ ⋄ ⍶⍙(⍹-1)⊢⍶⍵"; + } + + if(code) + return rundfn(code, lefto, righto, left, right); + else{ + throwerror(nil, EDomain); + return nil; + } } Array * |