lambda
This commit is contained in:
@@ -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"));
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,3 +141,7 @@
|
|||||||
|
|
||||||
(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)))))
|
||||||
Reference in New Issue
Block a user