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()); } }