(and ...)
This commit is contained in:
@@ -75,6 +75,31 @@ class Macros {
|
|||||||
]).withPos(args[0].pos);
|
]).withPos(args[0].pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// (and... uses (cond... ) and (not ...) under the hood)
|
||||||
|
macros["and"] = (args:Array<ReaderExp>, k) -> {
|
||||||
|
var uniqueVarName = "_" + Uuid.v4().toShort();
|
||||||
|
var uniqueVarSymbol = Symbol(uniqueVarName).withPos(args[0].pos);
|
||||||
|
|
||||||
|
var condCases = [
|
||||||
|
for (arg in args) {
|
||||||
|
CallExp(CallExp(Symbol("not").withPos(args[0].pos),
|
||||||
|
[
|
||||||
|
CallExp(Symbol("set").withPos(args[0].pos), [uniqueVarSymbol, arg]).withPos(args[0].pos)
|
||||||
|
]).withPos(args[0].pos), [Symbol("null").withPos(args[0].pos)]).withPos(args[0].pos);
|
||||||
|
}
|
||||||
|
];
|
||||||
|
condCases.push(CallExp(Symbol("true").withPos(args[0].pos), [uniqueVarSymbol]).withPos(args[0].pos));
|
||||||
|
|
||||||
|
CallExp(Symbol("begin").withPos(args[0].pos), [
|
||||||
|
CallExp(Symbol("deflocal").withPos(args[0].pos), [
|
||||||
|
TypedExp("Any", uniqueVarSymbol).withPos(args[0].pos),
|
||||||
|
MetaExp("mut").withPos(args[0].pos),
|
||||||
|
Symbol("null").withPos(args[0].pos)
|
||||||
|
]).withPos(args[0].pos),
|
||||||
|
CallExp(Symbol("cond").withPos(args[0].pos), condCases).withPos(args[0].pos)
|
||||||
|
]).withPos(args[0].pos);
|
||||||
|
};
|
||||||
|
|
||||||
// Under the hood, (defmacrofun ...) defines a runtime function that accepts Quote arguments and a special form that quotes the arguments to macrofun calls
|
// Under the hood, (defmacrofun ...) defines a runtime function that accepts Quote arguments and a special form that quotes the arguments to macrofun calls
|
||||||
macros["defmacrofun"] = (exps:Array<ReaderExp>, k:KissState) -> {
|
macros["defmacrofun"] = (exps:Array<ReaderExp>, k:KissState) -> {
|
||||||
if (exps.length < 3)
|
if (exps.length < 3)
|
||||||
|
|||||||
@@ -174,6 +174,12 @@ class BasicTestCase extends Test {
|
|||||||
Assert.equals(5, BasicTestCase.myOr1);
|
Assert.equals(5, BasicTestCase.myOr1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testAnd() {
|
||||||
|
Assert.equals(6, BasicTestCase.myAnd1);
|
||||||
|
Assert.equals(null, BasicTestCase.myAnd2);
|
||||||
|
Assert.equals(null, BasicTestCase.myAnd3);
|
||||||
|
}
|
||||||
|
|
||||||
function testNot() {
|
function testNot() {
|
||||||
Assert.equals(false, BasicTestCase.myNot1);
|
Assert.equals(false, BasicTestCase.myNot1);
|
||||||
Assert.equals(false, BasicTestCase.myNot2);
|
Assert.equals(false, BasicTestCase.myNot2);
|
||||||
|
|||||||
@@ -130,6 +130,10 @@
|
|||||||
|
|
||||||
(defvar myOr1 (or null 5))
|
(defvar myOr1 (or null 5))
|
||||||
|
|
||||||
|
(defvar myAnd1 (and 5 6))
|
||||||
|
(defvar myAnd2 (and false 5 6))
|
||||||
|
(defvar myAnd3 (and 5 false 6))
|
||||||
|
|
||||||
(defun mySetLocal []
|
(defun mySetLocal []
|
||||||
(deflocal loc &mut "one thing")
|
(deflocal loc &mut "one thing")
|
||||||
(set loc "another thing")
|
(set loc "another thing")
|
||||||
|
|||||||
4
src/test/cases/CommentAtEndOfListTestCase.kiss
Normal file
4
src/test/cases/CommentAtEndOfListTestCase.kiss
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
(defun myFun []
|
||||||
|
(deflocal something 5)
|
||||||
|
// TODO This comment causes a hard-to-track-down error!
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user