add function: exit

This commit is contained in:
Pekka Laiho 2020-10-17 14:47:30 +07:00
parent 5b2691d475
commit 72dc10f369
2 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -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);