test for modular macros
This commit is contained in:
@@ -19,4 +19,8 @@ class MacroTestCase extends Test {
|
|||||||
Assert.equals(6, sum1());
|
Assert.equals(6, sum1());
|
||||||
Assert.equals(6, sum2());
|
Assert.equals(6, sum2());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testModularMacros() {
|
||||||
|
Assert.equals("Nat 5", nameAndNumber("Nat", 5));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,4 +12,26 @@
|
|||||||
|
|
||||||
// Both forms of passing expression lists to macros should work:
|
// Both forms of passing expression lists to macros should work:
|
||||||
(defun sum1 [] (variadicPlus 1 2 3))
|
(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")
|
||||||
|
Reference in New Issue
Block a user