fez-lisp 1.5.20 → 1.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/check.js +1 -1
- package/src/compiler.js +4 -3
- package/src/interpreter.js +3 -7
- package/src/macros.js +14 -0
package/package.json
CHANGED
package/src/check.js
CHANGED
package/src/compiler.js
CHANGED
@@ -251,9 +251,10 @@ const comp = (tree, Drill) => {
|
|
251
251
|
case KEYWORDS.NOT:
|
252
252
|
return `(+!${comp(tail[0], Drill)})`
|
253
253
|
case KEYWORDS.IF: {
|
254
|
-
return `(${comp(tail[0], Drill)}?${comp(tail[1], Drill)}:${
|
255
|
-
tail
|
256
|
-
|
254
|
+
return `(${comp(tail[0], Drill)}?${comp(tail[1], Drill)}:${comp(
|
255
|
+
tail[2],
|
256
|
+
Drill
|
257
|
+
)});`
|
257
258
|
}
|
258
259
|
case KEYWORDS.LOOP: {
|
259
260
|
return `(()=>{while(${comp(tail[0], Drill)}){${comp(
|
package/src/interpreter.js
CHANGED
@@ -471,11 +471,11 @@ export const keywords = {
|
|
471
471
|
return array.length
|
472
472
|
},
|
473
473
|
[KEYWORDS.IF]: (args, env) => {
|
474
|
-
if (args.length
|
474
|
+
if (args.length !== 3)
|
475
475
|
throw new RangeError(
|
476
476
|
`Invalid number of arguments for (${
|
477
477
|
KEYWORDS.IF
|
478
|
-
}), expected (
|
478
|
+
}), expected (= 3) but got ${args.length}\n\n(${
|
479
479
|
KEYWORDS.IF
|
480
480
|
} ${stringifyArgs(args)})`
|
481
481
|
)
|
@@ -488,11 +488,7 @@ export const keywords = {
|
|
488
488
|
KEYWORDS.IF
|
489
489
|
} ${stringifyArgs(args)})`
|
490
490
|
)
|
491
|
-
return condition
|
492
|
-
? evaluate(args[1], env)
|
493
|
-
: args.length === 3
|
494
|
-
? evaluate(args[2], env)
|
495
|
-
: FALSE
|
491
|
+
return condition ? evaluate(args[1], env) : evaluate(args[2], env)
|
496
492
|
},
|
497
493
|
[KEYWORDS.NOT]: (args, env) => {
|
498
494
|
if (args.length !== 1)
|
package/src/macros.js
CHANGED
@@ -362,6 +362,20 @@ export const deSuggarAst = (ast, scope) => {
|
|
362
362
|
}
|
363
363
|
deSuggarAst(exp, scope)
|
364
364
|
break
|
365
|
+
case KEYWORDS.IF:
|
366
|
+
{
|
367
|
+
if (rest.length > 3 || rest.length < 2)
|
368
|
+
throw new RangeError(
|
369
|
+
`Invalid number of arguments for (${
|
370
|
+
KEYWORDS.IF
|
371
|
+
}), expected (or (= 3) (= 2)) but got ${rest.length} (${
|
372
|
+
KEYWORDS.IF
|
373
|
+
} ${stringifyArgs(rest)})`
|
374
|
+
)
|
375
|
+
if (rest.length === 2) exp.push([ATOM, FALSE])
|
376
|
+
}
|
377
|
+
deSuggarAst(exp[1], scope)
|
378
|
+
break
|
365
379
|
case SUGGAR.REMAINDER_OF_DIVISION_1:
|
366
380
|
{
|
367
381
|
if (rest.length !== 2)
|