add when, unless to portable macros
This commit is contained in:
@@ -241,21 +241,7 @@ class Macros {
|
||||
|
||||
function addBodyIf(keywordName:String, underlyingIf:String, negated:Bool) {
|
||||
k.doc(keywordName, 2, null, '($keywordName <condition> <body...>)');
|
||||
macros[keywordName] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k) -> {
|
||||
var b = wholeExp.expBuilder();
|
||||
var condition = if (negated) {
|
||||
b.call(
|
||||
b.symbol("not"), [
|
||||
args[0]
|
||||
]);
|
||||
} else {
|
||||
args[0];
|
||||
}
|
||||
return b.call(b.symbol(underlyingIf), [
|
||||
condition,
|
||||
b.begin(args.slice(1))
|
||||
]);
|
||||
};
|
||||
macros[keywordName] = wrapPortable(PortableMacros.bodyIf(underlyingIf, negated));
|
||||
}
|
||||
addBodyIf("when", "if", false);
|
||||
addBodyIf("unless", "if", true);
|
||||
|
||||
@@ -13,6 +13,8 @@ class PortableMacros {
|
||||
m["-="] = destructiveVersion("-");
|
||||
m["*="] = destructiveVersion("*");
|
||||
m["/="] = destructiveVersion("/");
|
||||
m["when"] = bodyIf("if", false);
|
||||
m["unless"] = bodyIf("if", true);
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -28,4 +30,22 @@ class PortableMacros {
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
||||
public static function bodyIf(underlyingIf:String, negated:Bool) {
|
||||
return (wholeExp:ReaderExp, args:Array<ReaderExp>) -> {
|
||||
var b = wholeExp.expBuilder();
|
||||
var condition = if (negated) {
|
||||
b.call(
|
||||
b.symbol("not"), [
|
||||
args[0]
|
||||
]);
|
||||
} else {
|
||||
args[0];
|
||||
}
|
||||
return b.call(b.symbol(underlyingIf), [
|
||||
condition,
|
||||
b.begin(args.slice(1))
|
||||
]);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user