added special form: undef

This commit is contained in:
Pekka Laiho 2020-12-08 16:13:40 +07:00
parent 07f9c7af8e
commit 86cba08088
2 changed files with 11 additions and 0 deletions

View File

@ -276,6 +276,7 @@ or | yes | `(or false 0 1)` | `1` | Return the first value that evaluates to
quote | yes | | | See the section Quoting. quote | yes | | | See the section Quoting.
quasiquote | yes | | | See the section Quoting. quasiquote | yes | | | See the section Quoting.
quasiquote-expand | yes | | | See the section Quoting. quasiquote-expand | yes | | | See the section Quoting.
undef | yes | `(undef myFn)` | `<function>` | Remove a definition from the current environment. Return the removed value.
## Functions ## Functions

View File

@ -367,6 +367,16 @@ class Evaller
} }
return $this->quasiquote($astData[1]); 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());
} }
} }