objectWith macro
This commit is contained in:
@@ -771,10 +771,34 @@ class Macros {
|
||||
// their original call stacks. This is more convenient for debugging than trying to
|
||||
// comment out the "try" and its catches, and re-balance parens
|
||||
macros["letThrow"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
wholeExp.checkNumArgs(1, null, "(letThrow [thing] [catches...])");
|
||||
wholeExp.checkNumArgs(1, null, "(letThrow <thing> <catches...>)");
|
||||
exps[0];
|
||||
};
|
||||
|
||||
macros["objectWith"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
wholeExp.checkNumArgs(1, null, "(objectWith <?[bindings...]> <fieldNames...>)");
|
||||
var objectExps = try {
|
||||
var l = Helpers.bindingList(exps[0], "field bindings for objectWith", true);
|
||||
exps.shift();
|
||||
l;
|
||||
} catch (_notABindingList) {
|
||||
[];
|
||||
}
|
||||
|
||||
for (exp in exps) {
|
||||
switch (exp.def) {
|
||||
case Symbol(_):
|
||||
objectExps.push(exp);
|
||||
objectExps.push(exp);
|
||||
default:
|
||||
throw CompileError.fromExp(exp, "invalid expression in (objectWith)");
|
||||
}
|
||||
}
|
||||
|
||||
var b = wholeExp.expBuilder();
|
||||
b.callSymbol("object", objectExps);
|
||||
}
|
||||
|
||||
// The wildest code in Kiss to date
|
||||
// TODO test exprCase!!
|
||||
macros["exprCase"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
|
@@ -164,10 +164,9 @@
|
||||
(set ktxt2Elements (KTxt2.splitFileElements (Stream.fromString text)))
|
||||
(doFor [idx element] (enumerate ktxt2Elements)
|
||||
(case element
|
||||
// TODO make an objectWith macro for case that duplicates parameter names with the match expressions:
|
||||
((Comment (object text text))
|
||||
((Comment (objectWith text))
|
||||
(commentElements text idx))
|
||||
((Block (object source source output output outputLocked outputLocked))
|
||||
((Block (objectWith source output outputLocked))
|
||||
(blockElements source output outputLocked idx))))
|
||||
}
|
||||
(catch [error] (print "Error updating ktxt2 editor: ${error}"))))
|
||||
|
Reference in New Issue
Block a user