whileLet
This commit is contained in:
@@ -748,6 +748,18 @@ class Macros {
|
|||||||
|
|
||||||
macros["awaitLet"] = awaitLet;
|
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
|
// TODO test defNew
|
||||||
macros["defnew"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
macros["defnew"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||||
wholeExp.checkNumArgs(1, null, "(defNew [[args...]] [[optional property bindings...]] [optional body...]");
|
wholeExp.checkNumArgs(1, null, "(defNew [[args...]] [[optional property bindings...]] [optional body...]");
|
||||||
|
@@ -4,6 +4,7 @@ import utest.Test;
|
|||||||
import utest.Assert;
|
import utest.Assert;
|
||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
import kiss.List;
|
import kiss.List;
|
||||||
|
import kiss.Stream;
|
||||||
import haxe.ds.Option;
|
import haxe.ds.Option;
|
||||||
|
|
||||||
using StringTools;
|
using StringTools;
|
||||||
@@ -341,6 +342,10 @@ class BasicTestCase extends Test {
|
|||||||
function testIntersect() {
|
function testIntersect() {
|
||||||
_testIntersect();
|
_testIntersect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testWhileLet() {
|
||||||
|
_testWhileLet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BasicObject {
|
class BasicObject {
|
||||||
|
@@ -629,3 +629,11 @@
|
|||||||
(assert (contains intersection3d "cy3"))
|
(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