From a328d13015fc4cbe34d99ddcfd36754e860dac00 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 26 Jan 2022 10:08:28 +0000 Subject: =?UTF-8?q?Implement=20a=20variant=20of=20execute=20=E2=8D=8E.=20M?= =?UTF-8?q?ine=20doesn't=20print=20the=20result=20of=20statements=20that?= =?UTF-8?q?=20aren't=20the=20result=20or=20are=20assigned.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apl9.h | 1 + functions.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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, /* ∇ */ }; @@ -714,6 +714,23 @@ fnTranspose(Array *right) return res; } +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) { -- cgit v1.2.3