summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-26 10:08:28 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-26 10:08:28 +0000
commita328d13015fc4cbe34d99ddcfd36754e860dac00 (patch)
treedfeb160260c20de742c9a3f3f8ee488016ce3050
parent794e0d2b6a7c8b15a302b0bb26c9d0d342d38a61 (diff)
Implement a variant of execute ⍎. Mine doesn't print the result of statements that aren't the result or are assigned.
-rw-r--r--apl9.h1
-rw-r--r--functions.c19
2 files changed, 19 insertions, 1 deletions
diff --git a/apl9.h b/apl9.h
index c56f356..4da1606 100644
--- a/apl9.h
+++ b/apl9.h
@@ -310,6 +310,7 @@ Array *fnShape(Array *);
Array *fnReverseLast(Array *);
Array *fnReverseFirst(Array *);
Array *fnTranspose(Array *);
+Array *fnExecute(Array *);
Array *fnSelfReference1(Array *);
/* Dyadic functions from function.c */
diff --git a/functions.c b/functions.c
index 9eb6406..c4b5cee 100644
--- a/functions.c
+++ b/functions.c
@@ -57,7 +57,7 @@ fnmonad monadfunctiondefs[] = {
fnReverseLast, /* ⌽ */
fnReverseFirst, /* ⊖ */
fnTranspose, /* ⍉ */
- 0, /* ⍎ */
+ fnExecute, /* ⍎ */
0, /* ⍕ */
fnSelfReference1, /* ∇ */
};
@@ -715,6 +715,23 @@ fnTranspose(Array *right)
}
Array *
+fnExecute(Array *right)
+{
+ if(right->type != AtypeRune)
+ throwerror(nil, EType);
+ Rune *code = pparray(right);
+ Datum *result = evalline(code, nil, 1);
+ free(code);
+ if(!result)
+ throwerror(L"No result produced by ⍎", EDomain);
+ if(result->tag != ArrayTag)
+ throwerror(L"Result of ⍎ must be an array", EType);
+ Array *res = result->array;
+ free(result);
+ return res;
+}
+
+Array *
fnSelfReference1(Array *right)
{
DfnFrame *dfn = getcurrentdfn();