From 235f448cfdf7b6c1f1664cd32fa769670bdd0d6c Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 17 Jan 2022 22:40:01 +0000 Subject: =?UTF-8?q?Implement=20monadic=20=E2=8D=AA=20(table)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apl9.h | 1 + functions.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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, /* ⊖ */ @@ -216,6 +216,17 @@ fnRavel(Array *right) return res; } +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) { -- cgit v1.2.3