summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-22 17:17:52 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-22 17:17:52 +0000
commit9edf00b19d92e2c78e7fea7fd9bfc48234037adc (patch)
treedce392b9038a8bd9443668ee8de9ac00434ecf74 /functions.c
parent9c93bc20cc68e50461bb086f24f335de9dcc5135 (diff)
Implement enlist (monadic ∊)
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/functions.c b/functions.c
index 2e0bfa2..f2b0d83 100644
--- a/functions.c
+++ b/functions.c
@@ -46,7 +46,7 @@ fnmonad monadfunctiondefs[] = {
fnGradeDown, /* ⍒ */
fnIndexGenerator, /* ⍳ */
0, /* ⍸ */
- 0, /* ∊ */
+ fnEnlist, /* ∊ */
0, /* ⍷ */
0, /* ∪ */
0, /* ∩ */
@@ -433,6 +433,15 @@ fnEnclose(Array *right)
}
Array *
+fnNest(Array *right)
+{
+ if(simplearray(right))
+ return fnEnclose(right);
+ else
+ return fnSame(right);
+}
+
+Array *
fnGradeUp(Array *right)
{
if(right->rank == 0)
@@ -493,12 +502,23 @@ fnIndexGenerator(Array *right)
}
Array *
-fnNest(Array *right)
+fnEnlist(Array *right)
{
- if(simplearray(right))
- return fnEnclose(right);
- else
+ if(right->size == 0)
return fnSame(right);
+ if(right->type != AtypeArray)
+ return fnRavel(right);
+ else{
+ Array *res = fnEnlist(right->arraydata[0]);
+ for(int i = 1; i < right->size; i++){
+ Array *old = res;
+ Array *tmp = fnEnlist(right->arraydata[i]);
+ res = fnCatenateFirst(res, tmp);
+ freearray(old);
+ freearray(tmp);
+ }
+ return res;
+ }
}
Array *