summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-17 22:40:01 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-17 22:40:01 +0000
commit235f448cfdf7b6c1f1664cd32fa769670bdd0d6c (patch)
treefdac6164038ad257699c0c3eeffb60380c65fa16
parent0ef01858ce7685cb2faac5a2cddc6a2fd76de104 (diff)
Implement monadic ⍪ (table)
-rw-r--r--apl9.h1
-rw-r--r--functions.c13
2 files changed, 13 insertions, 1 deletions
diff --git a/apl9.h b/apl9.h
index b96e793..8ec4e78 100644
--- a/apl9.h
+++ b/apl9.h
@@ -199,6 +199,7 @@ Array *fnEnclose(Array *);
Array *fnNest(Array *);
Array *fnIndexGenerator(Array *);
Array *fnRavel(Array *);
+Array *fnTable(Array *);
Array *fnShape(Array *);
Array *fnReverseLast(Array *);
Array *fnReverseFirst(Array *);
diff --git a/functions.c b/functions.c
index ef9aa97..eff944f 100644
--- a/functions.c
+++ b/functions.c
@@ -52,7 +52,7 @@ fnmonad monadfunctiondefs[] = {
0, /* ∩ */
0, /* ~ */
fnRavel, /* , */
- 0, /* ⍪ */
+ fnTable, /* ⍪ */
fnShape, /* ⍴ */
fnReverseLast, /* ⌽ */
fnReverseFirst, /* ⊖ */
@@ -217,6 +217,17 @@ fnRavel(Array *right)
}
Array *
+fnTable(Array *right)
+{
+ Array *res = duparray(right);
+ res->rank = 2;
+ res->shape = realloc(res->shape, sizeof(int) * 2);
+ res->shape[0] = right->rank ? res->shape[0] : 1;
+ res->shape[1] = right->size / res->shape[0];
+ return res;
+}
+
+Array *
fnShape(Array *right)
{
Array *res = allocarray(AtypeInt, 1, right->rank);