diff options
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) |