From 5d0d72d6ae6655c602f411135037d85059fb6106 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 26 Jun 2021 11:40:00 -0600 Subject: [PATCH] test for modular macros --- kiss/src/test/cases/MacroTestCase.hx | 4 ++++ kiss/src/test/cases/MacroTestCase.kiss | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/kiss/src/test/cases/MacroTestCase.hx b/kiss/src/test/cases/MacroTestCase.hx index 19499c67..f482efcc 100644 --- a/kiss/src/test/cases/MacroTestCase.hx +++ b/kiss/src/test/cases/MacroTestCase.hx @@ -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)); + } } diff --git a/kiss/src/test/cases/MacroTestCase.kiss b/kiss/src/test/cases/MacroTestCase.kiss index 30436044..f8989a19 100644 --- a/kiss/src/test/cases/MacroTestCase.kiss +++ b/kiss/src/test/cases/MacroTestCase.kiss @@ -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])) \ No newline at end of file +(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")