Close #5
This commit is contained in:
@@ -567,13 +567,15 @@ class Macros {
|
|||||||
var bindingList = exps[0].bindingList("ifLet");
|
var bindingList = exps[0].bindingList("ifLet");
|
||||||
var firstPattern = bindingList.shift();
|
var firstPattern = bindingList.shift();
|
||||||
var firstValue = bindingList.shift();
|
var firstValue = bindingList.shift();
|
||||||
|
var firstValueSymbol = b.symbol();
|
||||||
|
|
||||||
return b.call(
|
return b.callSymbol("let", [
|
||||||
b.symbol("if"), [
|
b.list([firstValueSymbol, firstValue]),
|
||||||
firstValue,
|
b.callSymbol("if", [
|
||||||
|
firstValueSymbol,
|
||||||
b.call(
|
b.call(
|
||||||
b.symbol("case"), [
|
b.symbol("case"), [
|
||||||
firstValue,
|
firstValueSymbol,
|
||||||
b.call(
|
b.call(
|
||||||
firstPattern, [
|
firstPattern, [
|
||||||
if (bindingList.length == 0) {
|
if (bindingList.length == 0) {
|
||||||
@@ -590,7 +592,8 @@ class Macros {
|
|||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
elseExp
|
elseExp
|
||||||
]);
|
])
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
macros["ifLet"] = ifLet;
|
macros["ifLet"] = ifLet;
|
||||||
@@ -598,23 +601,21 @@ class Macros {
|
|||||||
macros["whenLet"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
macros["whenLet"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||||
wholeExp.checkNumArgs(2, null, "(whenLet [[enum bindings...]] [body...])");
|
wholeExp.checkNumArgs(2, null, "(whenLet [[enum bindings...]] [body...])");
|
||||||
var b = wholeExp.expBuilder();
|
var b = wholeExp.expBuilder();
|
||||||
b.call(
|
b.callSymbol("ifLet", [
|
||||||
b.symbol("ifLet"), [
|
exps[0],
|
||||||
exps[0],
|
b.begin(exps.slice(1)),
|
||||||
b.begin(exps.slice(1)),
|
b.symbol("null")
|
||||||
b.symbol("null")
|
]);
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
macros["unlessLet"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
macros["unlessLet"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||||
wholeExp.checkNumArgs(2, null, "(unlessLet [[enum bindings...]] [body...])");
|
wholeExp.checkNumArgs(2, null, "(unlessLet [[enum bindings...]] [body...])");
|
||||||
var b = wholeExp.expBuilder();
|
var b = wholeExp.expBuilder();
|
||||||
b.call(
|
b.callSymbol("ifLet", [
|
||||||
b.symbol("ifLet"), [
|
exps[0],
|
||||||
exps[0],
|
b.symbol("null"),
|
||||||
b.symbol("null"),
|
b.begin(exps.slice(1))
|
||||||
b.begin(exps.slice(1))
|
]);
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO test this
|
// TODO test this
|
||||||
|
@@ -459,7 +459,13 @@
|
|||||||
(Assert.fail))
|
(Assert.fail))
|
||||||
(unlessLet [(Some (or 5 6)) some5]
|
(unlessLet [(Some (or 5 6)) some5]
|
||||||
(print "something else went wrong!")
|
(print "something else went wrong!")
|
||||||
(Assert.fail))))
|
(Assert.fail))
|
||||||
|
|
||||||
|
// Don't double evaluate the expression:
|
||||||
|
(let [&mut v 1]
|
||||||
|
(unlessLet [2 (begin (+= v 1) v)]
|
||||||
|
(Assert.fail))
|
||||||
|
(Assert.equals 2 v))))
|
||||||
|
|
||||||
(defun _testRawString []
|
(defun _testRawString []
|
||||||
(Assert.equals #| "\\" |# #"\"#)
|
(Assert.equals #| "\\" |# #"\"#)
|
||||||
|
Reference in New Issue
Block a user