From 72dc10f3698f9a5ef777350364b66347e1175891 Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Sat, 17 Oct 2020 14:47:30 +0700 Subject: [PATCH] add function: exit --- README.md | 1 + src/LispFactory.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index be9794d..a2042d5 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ doc | `(doc +)` | `"Return the sum of all arguments."` | Show description of a read | `(read "(+ 1 2 3)")` | `(+ 1 2 3)` | Read a string as code and return the expression. print | `(print "hello world")` | `"hello world"null` | Print expression on the screen. Print returns null (which is shown due to the extra print in repl). Give optional second argument as `true` to show strings in readable format. error | `(error "invalid value")` | `error: invalid value` | Throw an exception with message as argument. +exit | `(exit 1)` | | Terminate the script with given exit code using [exit](https://www.php.net/manual/en/function.exit.php). ### Collection functions diff --git a/src/LispFactory.php b/src/LispFactory.php index 2027d01..b562b5c 100644 --- a/src/LispFactory.php +++ b/src/LispFactory.php @@ -41,6 +41,12 @@ class LispFactory } )); + $env->set('exit', new CoreFunc('exit', 'Terminate the script with given exit code.', 0, 1, + function ($status = 0) { + exit($status); + } + )); + // Register core libraries (new Lib\Collections())->register($env); (new Lib\Compare())->register($env);