Arg num checks for and/or/not
This commit is contained in:
@@ -108,6 +108,7 @@ class Macros {
|
||||
|
||||
// (or... ) uses (cond... ) under the hood
|
||||
macros["or"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k) -> {
|
||||
wholeExp.checkNumArgs(2, null, "(or [v1] [v2] [values...])");
|
||||
var uniqueVarName = "_" + Uuid.v4().toShort();
|
||||
var uniqueVarSymbol = Symbol(uniqueVarName).withPos(args[0].pos);
|
||||
|
||||
@@ -126,6 +127,7 @@ class Macros {
|
||||
|
||||
// (and... uses (cond... ) and (not ...) under the hood)
|
||||
macros["and"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k) -> {
|
||||
wholeExp.checkNumArgs(2, null, "(and [v1] [v2] [values...])");
|
||||
var uniqueVarName = "_" + Uuid.v4().toShort();
|
||||
var uniqueVarSymbol = Symbol(uniqueVarName).withPosOf(wholeExp);
|
||||
|
||||
|
@@ -326,8 +326,7 @@ class SpecialForms {
|
||||
};
|
||||
|
||||
map["not"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
||||
if (args.length != 1)
|
||||
throw CompileError.fromExp(wholeExp, '(not... ) only takes one argument, not $args');
|
||||
wholeExp.checkNumArgs(1, 1, '(not [value])');
|
||||
var condition = k.convert(args[0]);
|
||||
var truthyExp = macro Prelude.truthy($condition);
|
||||
macro !$truthyExp;
|
||||
|
Reference in New Issue
Block a user