From 0df1eeecacb4f4e0c32e8d86320fca1efdc4bdda Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 21 Jan 2022 23:36:48 +0000 Subject: =?UTF-8?q?Implement=20=E2=88=98=20and=20fix=20a=20bug=20in=20simp?= =?UTF-8?q?lifyarray?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- operators.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'operators.c') diff --git a/operators.c b/operators.c index 65948de..32b9074 100644 --- a/operators.c +++ b/operators.c @@ -18,7 +18,7 @@ opmonad monadoperatordefs[] = { opdyad dyadoperatordefs[] = { 0, /* ⍣ */ 0, /* . */ - 0, /* ∘ */ + opBind, /* ∘ */ 0, /* ⍤ */ opOver, /* ⍥ */ 0, /* @ */ @@ -43,7 +43,7 @@ opEach(Datum *lefto, Array *left, Array *right) leftarr = nil; rightarr = fnSame(right); } - + Array *result = allocarray(AtypeArray, rightarr->rank, rightarr->size); for(i = 0; i < rightarr->rank; i++) result->shape[i] = rightarr->shape[i]; @@ -75,6 +75,26 @@ opSwitch(Datum *lefto, Array *left, Array *right) } /* Dyadic operators */ +Array * +opBind(Datum *lefto, Datum *righto, Array *left, Array *right) +{ + if(lefto->tag == FunctionTag && righto->tag == FunctionTag){ + Array *right1 = runfunc(righto->func, nil, right); + Array *result = runfunc(lefto->func, left, right1); + freearray(right1); + return result; + }else if(lefto->tag == FunctionTag && righto->tag == ArrayTag){ + if(left) + throwerror(L"The function doesn't take a left argument", ESyntax); + return runfunc(lefto->func, right, righto->array); + }else if(lefto->tag == ArrayTag && righto->tag == FunctionTag){ + if(left) + throwerror(L"The function doesn't take a left argument", ESyntax); + return runfunc(righto->func, lefto->array, right); + }else + return nil; +} + Array * opOver(Datum *lefto, Datum *righto, Array *left, Array *right) { -- cgit v1.2.3