This commit is contained in:
2020-11-25 13:59:28 -07:00
parent 90c7ba68da
commit 361e2a3c1c
4 changed files with 15 additions and 2 deletions

View File

@@ -50,6 +50,9 @@ class Reader {
readTable["!"] = (stream:Stream) -> CallExp(Symbol("not").withPos(stream.position()), [assertRead(stream, readTable)]); readTable["!"] = (stream:Stream) -> CallExp(Symbol("not").withPos(stream.position()), [assertRead(stream, readTable)]);
// Helpful for defining predicates to pass to Haxe functions:
readTable["?"] = (stream:Stream) -> CallExp(Symbol("Prelude.truthy").withPos(stream.position()), [assertRead(stream, readTable)]);
// Because macro keys are sorted by length and peekChars(0) returns "", this will be used as the default reader macro: // Because macro keys are sorted by length and peekChars(0) returns "", this will be used as the default reader macro:
readTable[""] = (stream) -> Symbol(nextToken(stream, "a symbol name")); readTable[""] = (stream) -> Symbol(nextToken(stream, "a symbol name"));

View File

@@ -110,7 +110,9 @@ class SpecialForms {
EBlock([EVars(varDefs).withContextPos(), EBlock(body.map(convert)).withContextPos()]).withContextPos(); EBlock([EVars(varDefs).withContextPos(), EBlock(body.map(convert)).withContextPos()]).withContextPos();
}; };
// TODO special form for lambda map["lambda"] = (args:Array<ReaderExp>, convert:ExprConversion) -> {
EFunction(FArrow, Helpers.makeFunction(null, args[0], args.slice(1), convert)).withContextPos();
};
// TODO special form for for loop // TODO special form for for loop
// TODO special form for list comprehension // TODO special form for list comprehension

View File

@@ -184,4 +184,8 @@ class BasicTestCase extends Test {
Assert.equals(false, BasicTestCase.myNot1); Assert.equals(false, BasicTestCase.myNot1);
Assert.equals(false, BasicTestCase.myNot2); Assert.equals(false, BasicTestCase.myNot2);
} }
function testLambda() {
Assert.equals([5, 6].toString(), BasicTestCase.myFilteredList.toString());
}
} }

View File

@@ -140,4 +140,8 @@
loc) loc)
(defvar myNot1 (not 5)) (defvar myNot1 (not 5))
(defvar myNot2 !5) (defvar myNot2 !5)
(defvar myFilteredList (begin
(deflocal l [-1 -2 5 -3 6])
(l.filter (lambda [v] (< 0 v)))))