From 496e1c2c2e4ad0df9069058fa132774a126cfa49 Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Sun, 6 Dec 2020 08:31:14 +0700 Subject: [PATCH] support for macros in Types lib --- src/Lib/Types.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Lib/Types.php b/src/Lib/Types.php index 1b7ee99..5e92aab 100644 --- a/src/Lib/Types.php +++ b/src/Lib/Types.php @@ -46,7 +46,11 @@ class Types implements ILib $env->set('type', new CoreFunc('type', 'Return the type of argument as a string.', 1, 1, function ($a) { if ($a instanceof Func) { - return 'function'; + if ($a->isMacro()) { + return 'macro'; + } else { + return 'function'; + } } elseif ($a instanceof MList) { return 'list'; } elseif ($a instanceof Vector) { @@ -74,9 +78,14 @@ class Types implements ILib )); $env->set('fn?', new CoreFunc('fn?', 'Return true if argument is a function.', 1, 1, + // This returns true for macros as well, because they are functions fn ($a) => $a instanceof Func )); + $env->set('macro?', new CoreFunc('macro?', 'Return true if argument is a macro.', 1, 1, + fn ($a) => $a instanceof Func && $a->isMacro() + )); + $env->set('list?', new CoreFunc('list?', 'Return true if argument is a list.', 1, 1, fn ($a) => $a instanceof MList ));