(continue), (break)

This commit is contained in:
2020-12-01 16:15:02 -07:00
parent 2c67ba9473
commit 0f30d5d2e7
3 changed files with 27 additions and 1 deletions

View File

@@ -182,6 +182,16 @@ class SpecialForms {
EReturn(k.convert(args[0])).withMacroPosOf(wholeExp);
};
map["break"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(0, 0, "(break)");
EBreak.withMacroPosOf(wholeExp);
};
map["continue"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(0, 0, "(continue)");
EContinue.withMacroPosOf(wholeExp);
};
// TODO (case... ) for switch
// Type check syntax:

View File

@@ -232,4 +232,8 @@ class BasicTestCase extends Test {
function testFieldExps() {
_testFieldExps();
}
function testBreakContinue() {
_testBreakContinue();
}
}

View File

@@ -262,4 +262,16 @@
(defun _testFieldExps []
(Assert.equals "hey" (.trim " hey "))
(Assert.equals "e" (.charAt (.trim " hey ") 1)))
(Assert.equals "e" (.charAt (.trim " hey ") 1)))
(defun _testBreakContinue []
(let [[a b c]
(for val [1 2 3 4 5 6 7 8]
(if (> val 6)
(break)
(if (% val 2)
(continue)
val)))]
(Assert.equals 2 a)
(Assert.equals 4 b)
(Assert.equals 6 c)))