Test macro list expansion
This commit is contained in:
@@ -292,7 +292,18 @@ class Helpers {
|
||||
switch (l[idx].def) {
|
||||
case UnquoteList(exp):
|
||||
l.splice(idx, 1);
|
||||
var newElements:Array<ReaderExp> = runAtCompileTime(exp, k, args);
|
||||
var listToInsert:Dynamic = runAtCompileTime(exp, k, args);
|
||||
// listToInsert could be either an array (from &rest) or a ListExp (from [list syntax])
|
||||
var newElements:Array<ReaderExp> = if (Std.isOfType(listToInsert, Array)) {
|
||||
listToInsert;
|
||||
} else {
|
||||
switch (listToInsert.def) {
|
||||
case ListExp(elements):
|
||||
elements;
|
||||
default:
|
||||
throw CompileError.fromExp(l[idx], ",@ can only be used with lists");
|
||||
};
|
||||
};
|
||||
for (el in newElements) {
|
||||
l.insert(idx++, el);
|
||||
}
|
||||
|
@@ -14,4 +14,9 @@ class MacroTestCase extends Test {
|
||||
Assert.equals(5, myVar);
|
||||
Assert.equals(6, myFunc());
|
||||
}
|
||||
|
||||
function testExpandList() {
|
||||
Assert.equals(6, sum1());
|
||||
Assert.equals(6, sum2());
|
||||
}
|
||||
}
|
||||
|
@@ -3,4 +3,13 @@
|
||||
(defvar ,varName 5)
|
||||
(defun ,funcName [] 6)})
|
||||
|
||||
(defMultiple myVar myFunc)
|
||||
(defMultiple myVar myFunc)
|
||||
|
||||
(defmacro variadicPlus [&rest l]
|
||||
`(+ ,@l))
|
||||
(defmacro listPlus [l]
|
||||
`(+ ,@l))
|
||||
|
||||
// Both forms of passing expression lists to macros should work:
|
||||
(defun sum1 [] (variadicPlus 1 2 3))
|
||||
(defun sum2 [] (listPlus [1 2 3]))
|
Reference in New Issue
Block a user