fez-lisp 1.5.105 → 1.5.107

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "fez-lisp",
3
3
  "description": "Lisp interpreted & compiled to JavaScript",
4
4
  "author": "AT290690",
5
- "version": "1.5.105",
5
+ "version": "1.5.107",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -34,7 +34,8 @@ import {
34
34
  ANY,
35
35
  formatType,
36
36
  ANONYMOUS_FUNCTION_TYPE_PREFIX,
37
- validateLambda
37
+ validateLambda,
38
+ NIL
38
39
  } from './types.js'
39
40
  import {
40
41
  Brr,
package/src/macros.js CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  WORD
17
17
  } from './keywords.js'
18
18
  import { hasBlock, stringifyArgs } from './utils.js'
19
+ import { NIL } from './types.js'
19
20
  export const SUGGAR = {
20
21
  // Syntactic suggars
21
22
  PIPE: '|>',
@@ -121,11 +122,11 @@ export const deSuggarAst = (ast, scope) => {
121
122
  break
122
123
  case SUGGAR.CONDITION:
123
124
  {
124
- if (rest.length < 2)
125
+ if (rest.length < 4)
125
126
  throw new RangeError(
126
127
  `Invalid number of arguments for (${
127
128
  SUGGAR.CONDITION
128
- }), expected (> 2 required) but got ${rest.length} (${
129
+ }), expected (> 3 required) but got ${rest.length} (${
129
130
  SUGGAR.CONDITION
130
131
  } ${stringifyArgs(rest)})`
131
132
  )
@@ -137,11 +138,25 @@ export const deSuggarAst = (ast, scope) => {
137
138
  rest.length
138
139
  } (${SUGGAR.CONDITION} ${stringifyArgs(rest)})`
139
140
  )
141
+ if (rest.at(-2)[0][VALUE] !== KEYWORDS.MULTIPLICATION) {
142
+ throw new ReferenceError(
143
+ `Last condition of (${
144
+ SUGGAR.CONDITION
145
+ }), has to be a wildcard (${KEYWORDS.MULTIPLICATION}) (${
146
+ SUGGAR.CONDITION
147
+ }) followed by a default result (${stringifyArgs(exp)}))`
148
+ )
149
+ }
140
150
  exp.length = 0
141
151
  let temp = exp
142
152
  for (let i = 0; i < rest.length; i += 2) {
143
153
  if (i === rest.length - 2) {
144
- temp.push([APPLY, KEYWORDS.IF], rest[i], rest.at(-1))
154
+ temp.push(
155
+ [APPLY, KEYWORDS.IF],
156
+ rest[i],
157
+ rest.at(-1),
158
+ rest.at(-1)
159
+ )
145
160
  } else {
146
161
  temp.push([APPLY, KEYWORDS.IF], rest[i], rest[i + 1], [])
147
162
  temp = temp.at(-1)
@@ -357,7 +372,7 @@ export const deSuggarAst = (ast, scope) => {
357
372
  )
358
373
  exp[0][VALUE] = KEYWORDS.IF
359
374
  const temp = exp[2]
360
- exp[2] = exp[3] ?? [ATOM, FALSE]
375
+ exp[2] = exp[3] ?? [WORD, NIL]
361
376
  exp[3] = temp
362
377
  }
363
378
  deSuggarAst(exp, scope)
@@ -372,7 +387,7 @@ export const deSuggarAst = (ast, scope) => {
372
387
  KEYWORDS.IF
373
388
  } ${stringifyArgs(rest)})`
374
389
  )
375
- if (rest.length === 2) exp.push([ATOM, FALSE])
390
+ if (rest.length === 2) exp.push([WORD, NIL])
376
391
  }
377
392
  deSuggarAst(exp[1], scope)
378
393
  break
package/src/types.js CHANGED
@@ -24,6 +24,7 @@ export const ANY = 5
24
24
  export const ANONYMOUS_FUNCTION_TYPE_PREFIX = 'lambda::annonymous::'
25
25
  export const MAX_ARGUMENT_RETRY = 1
26
26
  export const MAX_RETRY_DEFINITION = 100
27
+ export const NIL = 'nil'
27
28
  export const toTypeNames = (type) => {
28
29
  switch (type) {
29
30
  case APPLY: