From 86cba08088fa4bebb0a08d20a5624178e19ddcbf Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Tue, 8 Dec 2020 16:13:40 +0700 Subject: [PATCH] added special form: undef --- README.md | 1 + src/Evaller.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 99c3cf1..7555fa7 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,7 @@ or | yes | `(or false 0 1)` | `1` | Return the first value that evaluates to quote | yes | | | See the section Quoting. quasiquote | yes | | | See the section Quoting. quasiquote-expand | yes | | | See the section Quoting. +undef | yes | `(undef myFn)` | `` | Remove a definition from the current environment. Return the removed value. ## Functions diff --git a/src/Evaller.php b/src/Evaller.php index 7cc9ad9..cacc8c5 100644 --- a/src/Evaller.php +++ b/src/Evaller.php @@ -367,6 +367,16 @@ class Evaller } return $this->quasiquote($astData[1]); + } elseif ($symbolName == 'undef') { + if ($astLength != 2) { + throw new MadLispException("undef requires exactly 1 argument"); + } + + if (!($astData[1] instanceof Symbol)) { + throw new MadLispException("first argument to undef is not symbol"); + } + + return $env->unset($astData[1]->getName()); } }