diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-21 23:36:48 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-21 23:36:48 +0000 |
commit | 0df1eeecacb4f4e0c32e8d86320fca1efdc4bdda (patch) | |
tree | e93f29ef225910ad51b0787990ec871c11dcae8e /operators.c | |
parent | 12e1d1fe6464964b2bee1b83b8524445fc2bbe2c (diff) |
Implement ∘ and fix a bug in simplifyarray
Diffstat (limited to 'operators.c')
-rw-r--r-- | operators.c | 24 |
1 files changed, 22 insertions, 2 deletions
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]; @@ -76,6 +76,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) { if(lefto->tag != FunctionTag || righto->tag != FunctionTag) |