git » jacl.git » commit 14d9f59

Fix required arg calc, error if arg not sym

author Alan Dipert
2019-10-11 05:11:10 UTC
committer Alan Dipert
2019-10-11 05:11:10 UTC
parent ab1c5b1e982aff65cc55adbac780b2bd97f14ff3

Fix required arg calc, error if arg not sym

jacl.js +6 -2

diff --git a/jacl.js b/jacl.js
index dff0ae0..c5f5f46 100644
--- a/jacl.js
+++ b/jacl.js
@@ -740,7 +740,11 @@ const analyzeSpecials = new Map([
   [JACLPKG.intern("%LAMBDA"), (env, form) => {
     const [, arglist, ...exprs] = form,
           args                  = (arglist === null ? [] : Array.from(arglist))
-                                    .map(x => x.name),
+                                    .map(x => {
+                                      if (!(x instanceof LispSymbol))
+                                        throw new Error(`Args must be symbols`);
+                                      return x.name;
+                                    }),
           restIdx               = args.findIndex(x => x === '&REST'),
           isVariadic            = restIdx >= 0,
           argNames              = args.filter(x => x !== '&REST');
@@ -757,7 +761,7 @@ const analyzeSpecials = new Map([
       env: env,
       form: form,
       isVariadic: isVariadic,
-      minArgs: argNames.length,
+      minArgs: argNames.length - (isVariadic ? 1 : 0),
       argNames: argNames,
       restArgName: isVariadic ? args[restIdx+1] : null
     }, analyzeBlock(bodyEnv, exprs));