test for modular macros

This commit is contained in:
2021-06-26 11:40:00 -06:00
parent 2322668af5
commit 5d0d72d6ae
2 changed files with 27 additions and 1 deletions

View File

@@ -19,4 +19,8 @@ class MacroTestCase extends Test {
Assert.equals(6, sum1());
Assert.equals(6, sum2());
}
function testModularMacros() {
Assert.equals("Nat 5", nameAndNumber("Nat", 5));
}
}

View File

@@ -12,4 +12,26 @@
// Both forms of passing expression lists to macros should work:
(defun sum1 [] (variadicPlus 1 2 3))
(defun sum2 [] (listPlus [1 2 3]))
(defun sum2 [] (listPlus [1 2 3]))
// You should be able to run list comprehensions on expressions
// and put the pieces back together in a modular way
(defmacro altDefun [name args &rest body]
(let [argPairs
(groups (expList args) 2)
untypedArgs
[]
letBindings
[]]
(doFor [name type] argPairs
(untypedArgs.push name)
(letBindings.push name)
(print type)
(print name)
(letBindings.push `(the ,type ,name)))
(print letBindings)
`(defun ,name ,untypedArgs
(let ,letBindings ,@body))))
(altDefun nameAndNumber [name String number Int]
"$name $number")