diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-17 22:40:01 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-17 22:40:01 +0000 |
commit | 235f448cfdf7b6c1f1664cd32fa769670bdd0d6c (patch) | |
tree | fdac6164038ad257699c0c3eeffb60380c65fa16 | |
parent | 0ef01858ce7685cb2faac5a2cddc6a2fd76de104 (diff) |
Implement monadic ⍪ (table)
-rw-r--r-- | apl9.h | 1 | ||||
-rw-r--r-- | functions.c | 13 |
2 files changed, 13 insertions, 1 deletions
@@ -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); |