while & until
This commit is contained in:
@@ -243,10 +243,22 @@ class SpecialForms {
|
|||||||
};
|
};
|
||||||
|
|
||||||
map["loop"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
map["loop"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
||||||
wholeExp.checkNumArgs(1, null, '(loop [body...])');
|
wholeExp.checkNumArgs(1, null, '(loop <body...>)');
|
||||||
EWhile(macro true, k.convert(wholeExp.expBuilder().begin(args)), true).withMacroPosOf(wholeExp);
|
EWhile(macro true, k.convert(wholeExp.expBuilder().begin(args)), true).withMacroPosOf(wholeExp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function whileForm(invert:Bool, wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) {
|
||||||
|
var funcName = if (invert) "until" else "while";
|
||||||
|
wholeExp.checkNumArgs(2, null, '($funcName <condition> <body...>)');
|
||||||
|
var b = wholeExp.expBuilder();
|
||||||
|
var cond = k.convert(b.callSymbol("Prelude.truthy", [args[0]]));
|
||||||
|
if (invert) cond = macro !$cond;
|
||||||
|
return EWhile(cond, k.convert(b.begin(args)), true).withMacroPosOf(wholeExp);
|
||||||
|
}
|
||||||
|
|
||||||
|
map["while"] = whileForm.bind(false);
|
||||||
|
map["until"] = whileForm.bind(true);
|
||||||
|
|
||||||
map["return"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
map["return"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
||||||
wholeExp.checkNumArgs(0, 1, '(return [?value])');
|
wholeExp.checkNumArgs(0, 1, '(return [?value])');
|
||||||
var returnExpr = if (args.length == 1) k.convert(args[0]) else null;
|
var returnExpr = if (args.length == 1) k.convert(args[0]) else null;
|
||||||
|
Reference in New Issue
Block a user