whileLet
This commit is contained in:
@@ -747,6 +747,18 @@ class Macros {
|
||||
}
|
||||
|
||||
macros["awaitLet"] = awaitLet;
|
||||
|
||||
macros["whileLet"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
wholeExp.checkNumArgs(2, null, "(whileLet [<bindings...>] <body...>)");
|
||||
var b = wholeExp.expBuilder();
|
||||
return b.callSymbol("loop", [
|
||||
b.callSymbol("ifLet", [
|
||||
exps[0],
|
||||
b.begin(exps.slice(1)),
|
||||
b.callSymbol("break", [])
|
||||
])
|
||||
]);
|
||||
};
|
||||
|
||||
// TODO test defNew
|
||||
macros["defnew"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
|
@@ -4,6 +4,7 @@ import utest.Test;
|
||||
import utest.Assert;
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import kiss.Stream;
|
||||
import haxe.ds.Option;
|
||||
|
||||
using StringTools;
|
||||
@@ -341,6 +342,10 @@ class BasicTestCase extends Test {
|
||||
function testIntersect() {
|
||||
_testIntersect();
|
||||
}
|
||||
|
||||
function testWhileLet() {
|
||||
_testWhileLet();
|
||||
}
|
||||
}
|
||||
|
||||
class BasicObject {
|
||||
|
@@ -628,4 +628,12 @@
|
||||
(assert (contains intersection3d "cy1"))
|
||||
(assert (contains intersection3d "cy3"))
|
||||
)
|
||||
(Assert.pass))
|
||||
(Assert.pass))
|
||||
|
||||
(function _testWhileLet []
|
||||
(let [&mut idx 0
|
||||
lines ["a" "b" "c"]
|
||||
stream (Stream.fromString "a\nb\nc")]
|
||||
(whileLet [(Some line) (stream.takeLine)]
|
||||
(Assert.equals (nth lines idx) line)
|
||||
(+= idx 1))))
|
Reference in New Issue
Block a user