collectWhileLet
This commit is contained in:
@@ -839,6 +839,22 @@ class Macros {
|
||||
]);
|
||||
};
|
||||
|
||||
k.doc("collectWhileLet", 2, null, "(collectWhileLet [<bindings...>] <body...>)");
|
||||
macros["collectWhileLet"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
var b = wholeExp.expBuilder();
|
||||
var results = b.symbol();
|
||||
var nextExp = b.symbol();
|
||||
var body = b.begin(exps.slice(1));
|
||||
return b.let([results, b.list([])], [
|
||||
b.callSymbol("whileLet", [
|
||||
exps[0],
|
||||
b.let([nextExp, body],
|
||||
[b.callField("push", results, [nextExp])])
|
||||
]),
|
||||
results
|
||||
]);
|
||||
};
|
||||
|
||||
k.doc("withTempSet", 2, null, "(withTempSet [<bindings...>] <body...>)");
|
||||
macros["withTempSet"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
var b = wholeExp.expBuilder();
|
||||
|
@@ -679,7 +679,14 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
|
||||
stream (Stream.fromString "a\nb\nc")]
|
||||
(whileLet [(Some line) (stream.takeLine)]
|
||||
(Assert.equals (nth lines idx) line)
|
||||
(+= idx 1))))
|
||||
(+= idx 1)))
|
||||
(let [lines ["a" "b" "c"]
|
||||
options [(Some "a") (Some "b") (Some "c") None]
|
||||
collected
|
||||
(collectWhileLet [(Some line) (options.shift)]
|
||||
line)]
|
||||
(doFor i (range collected.length)
|
||||
(Assert.equals (nth lines i) (nth collected i)))))
|
||||
|
||||
(function _testTrace []
|
||||
(Assert.equals 5 (trace 5 "num"))
|
||||
|
Reference in New Issue
Block a user