Arg num checks for and/or/not

This commit is contained in:
2021-01-04 09:03:44 -07:00
parent a2555dc0c1
commit 8e96bc5288
2 changed files with 3 additions and 2 deletions

View File

@@ -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);

View File

@@ -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;