undefmacro

This commit is contained in:
2021-07-22 16:36:30 -06:00
parent b54073fa32
commit a15bfe7da3
3 changed files with 22 additions and 3 deletions

View File

@@ -339,8 +339,6 @@ class Macros {
macros["defmacro"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(3, null, '(defmacro [name] [[args...]] [body...])');
var table = k.macros;
var name = switch (exps[0].def) {
case Symbol(name): name;
default: throw CompileError.fromExp(exps[0], "macro name should be a symbol");
@@ -439,6 +437,18 @@ class Macros {
null;
};
macros["undefmacro"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(1, 1, '(undefmacro [name])');
var name = switch (exps[0].def) {
case Symbol(name): name;
default: throw CompileError.fromExp(exps[0], "macro name should be a symbol");
};
k.macros.remove(name);
null;
};
macros["defreadermacro"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(3, null, '(defreadermacro [optional &start] ["[startingString]" or [startingStrings...]] [[streamArgName]] [body...])');

View File

@@ -28,4 +28,8 @@ class MacroTestCase extends Test {
Assert.equals(9, print);
Assert.equals(9, aliasValue());
}
function testUndefMacro() {
Assert.equals(11, andValue());
}
}

View File

@@ -43,4 +43,9 @@
(defalias &ident alias 5)
(undefalias &ident alias)
(defvar alias 9)
(defun aliasValue [] alias)
(defun aliasValue [] alias)
// If for whatever reason, you wanted to make a function called and
(undefmacro and)
(defun and [a b] (+ a b))
(defun andValue [] (and 5 6))