From 3ad61539a385847d528d1efd20f1cfa5061fc071 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 24 Jan 2022 22:26:08 +0000 Subject: =?UTF-8?q?Implement=20a=20better=20version=20of=20=E2=8D=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- operators.c | 24 +++++++++++++++++++++--- 1 file 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 * -- cgit v1.2.3