summaryrefslogtreecommitdiff
path: root/operators.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-24 22:26:08 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-24 22:26:08 +0000
commit3ad61539a385847d528d1efd20f1cfa5061fc071 (patch)
tree5a8b69263a1ea6dccfcb03a59ebe38472d470606 /operators.c
parente77ed10bf640bf6c3cb6ce10943e0be6e82f5250 (diff)
Implement a better version of ⍣
Diffstat (limited to 'operators.c')
-rw-r--r--operators.c24
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 *