diff --git a/README.md b/README.md index 509583c..0bd81c8 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,7 @@ quote | `(quote (1 2 3))` | `(1 2 3)` | Return the argument without evaluation. Name | Example | Example result | Description ----- | ------- | -------------- | ----------- +debug | `(debug)` | `true` | Toggle debug output. doc | `(doc +)` | `"Return the sum of all arguments."` | Show description of a built-in function. loop | `(loop (fn (a) (do (print a) (coinflip))) "hello ")` | `hello hello hello false` | Call the given function repeatedly in a loop until it returns false. meta | `(meta (env) "name")` | `"root/user"` | Read meta information of an entity. diff --git a/src/Evaller.php b/src/Evaller.php index e6bddb4..ff75bf9 100644 --- a/src/Evaller.php +++ b/src/Evaller.php @@ -294,6 +294,11 @@ class Evaller } } + public function getDebug(): bool + { + return $this->debug; + } + public function setDebug(bool $val): void { $this->debug = $val; diff --git a/src/LispFactory.php b/src/LispFactory.php index f77a73a..d0308fb 100644 --- a/src/LispFactory.php +++ b/src/LispFactory.php @@ -18,6 +18,14 @@ class LispFactory $env->set('__DIR__', null); // Register core functions + $env->set('debug', new CoreFunc('debug', 'Toggle debug mode.', 0, 0, + function () use ($eval) { + $val = !$eval->getDebug(); + $eval->setDebug($val); + return $val; + } + )); + $env->set('doc', new CoreFunc('doc', 'Get documentation for a function.', 1, 1, function ($a) { if ($a instanceof Func) {