diff --git a/src/kiss/SpecialForms.hx b/src/kiss/SpecialForms.hx index 66e0317..7b1829a 100644 --- a/src/kiss/SpecialForms.hx +++ b/src/kiss/SpecialForms.hx @@ -334,7 +334,7 @@ class SpecialForms { function whileForm(invert:Bool, wholeExp:ReaderExp, args:Array, k:KissState) { var funcName = if (invert) "until" else "while"; var b = wholeExp.expBuilder(); - var cond = k.convert(b.callSymbol("Prelude.truthy", [args[0]])); + var cond = k.convert(b.callSymbol("Prelude.truthy", [args.shift()])); if (invert) { cond = macro !$cond; cond = b.haxeExpr(cond); diff --git a/src/test/cases/BasicTestCase.hx b/src/test/cases/BasicTestCase.hx index de37117..66301bc 100644 --- a/src/test/cases/BasicTestCase.hx +++ b/src/test/cases/BasicTestCase.hx @@ -355,6 +355,10 @@ class BasicTestCase extends Test { _testIntersect(); } + function testWhile() { + _testWhile(); + } + function testWhileLet() { _testWhileLet(); } diff --git a/src/test/cases/BasicTestCase.kiss b/src/test/cases/BasicTestCase.kiss index fc2829a..8a1e36e 100644 --- a/src/test/cases/BasicTestCase.kiss +++ b/src/test/cases/BasicTestCase.kiss @@ -675,6 +675,14 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m ) (Assert.pass)) +(function _testWhile [] + (let [max 8 + &mut current 0 + &mut iterations 0] + (while (>= max (+= current 1)) + (+= iterations 1)) + (Assert.equals 8 iterations))) + (function _testWhileLet [] (let [&mut idx 0 lines ["a" "b" "c"]