(when...)

This commit is contained in:
2020-11-27 22:16:28 -07:00
parent 7642ca3b36
commit 680880d527
3 changed files with 13 additions and 2 deletions

View File

@@ -52,7 +52,12 @@ class Macros {
macros["_eq"] = foldMacro("Prelude.areEqual");
// TODO when
macros["when"] = (args:Array<ReaderExp>, k) -> {
CallExp(Symbol("if").withPos(args[0].pos), [
args[0],
CallExp(Symbol("begin").withPos(args[0].pos), args.slice(1)).withPos(args[0].pos)
]).withPos(args[0].pos);
};
macros["cond"] = cond;

View File

@@ -190,4 +190,8 @@ class BasicTestCase extends Test {
function testLambda() {
Assert.equals([5, 6].toString(), BasicTestCase.myFilteredList.toString());
}
function testWhen() {
Assert.equals(6, BasicTestCase.myWhen1);
}
}

View File

@@ -146,4 +146,6 @@
(defvar myFilteredList (begin
(deflocal l [-1 -2 5 -3 6])
(l.filter (lambda [v] (< 0 v)))))
(l.filter (lambda [v] (< 0 v)))))
(defvar myWhen1 (when true 5 6))