summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-28 15:40:40 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-28 15:40:40 +0000
commit22858219b44dcc483aecc40297cea28a02625972 (patch)
tree6431310fe8bfcf62a89fe4129bd42e6a9e7874b7 /functions.c
parent69d4a8f20cbc60bae27aef9a36857324a04c581f (diff)
Implement membership (X∊Y), excluding (X~Y) and union (X∪Y)
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/functions.c b/functions.c
index eedacb9..ad87c11 100644
--- a/functions.c
+++ b/functions.c
@@ -102,11 +102,11 @@ fndyad dyadfunctiondefs[] = {
0, /* ⍒ */
0, /* ⍳ */
0, /* ⍸ */
- 0, /* ∊ */
+ fnMembership, /* ∊ */
0, /* ⍷ */
- 0, /* ∪ */
+ fnUnion, /* ∪ */
0, /* ∩ */
- 0, /* ~ */
+ fnExcluding, /* ~ */
fnCatenateLast, /* , */
fnCatenateFirst, /* ⍪ */
fnReshape, /* ⍴ */
@@ -1137,6 +1137,27 @@ fnIndex(Array *left, Array *right)
}
Array *
+fnMembership(Array *left, Array *right)
+{
+ /* TODO avoid outer product */
+ return rundfn(L"∨/⍺≡⌾⍵", nil, nil, left, right);
+}
+
+Array *
+fnUnion(Array *left, Array *right)
+{
+ if(left->rank > 1 || right->rank > 1)
+ throwerror(nil, ERank);
+ return rundfn(L"⍺⍪⍵~⍺", nil, nil, left, right);
+}
+
+Array *
+fnExcluding(Array *left, Array *right)
+{
+ return rundfn(L"(~⍺∊⍵)⌿⍺", nil, nil, left, right);
+}
+
+Array *
fnCatenateLast(Array *left, Array *right)
{
return rundfn(L"⍉(⍉⍺)⍪⍉⍵", nil, nil, left, right);