fez-lisp 1.5.40 → 1.5.42

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/src/compiler.js CHANGED
@@ -145,8 +145,6 @@ const comp = (tree, Drill) => {
145
145
  if (isLeaf(tree)) head = tree
146
146
  else {
147
147
  head = tree[0]
148
- if (head == undefined) return '[];'
149
-
150
148
  tail = tree.slice(1)
151
149
  }
152
150
  const token = head[VALUE]
package/src/evaluator.js CHANGED
@@ -16,7 +16,6 @@ export const evaluate = (exp, env = keywords) => {
16
16
  if (isLeaf(exp)) head = exp
17
17
  else {
18
18
  head = exp[0]
19
- if (head == undefined) return []
20
19
  tail = exp.slice(1)
21
20
  }
22
21
  const value = head[VALUE]
package/src/macros.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  VALUE,
17
17
  WORD
18
18
  } from './keywords.js'
19
- import { hasBlock, stringifyArgs } from './utils.js'
19
+ import { getSuffix, hasBlock, stringifyArgs } from './utils.js'
20
20
  export const SUGGAR = {
21
21
  // Syntactic suggars
22
22
  PIPE: '|>',
@@ -524,7 +524,7 @@ export const deSuggarAst = (ast, scope) => {
524
524
  const name = exp[1][VALUE]
525
525
  const prefix = name.split(':')[0]
526
526
  if (prefix === OPTIMIZATIONS.RECURSION) {
527
- if (name[name.length - 1] === PREDICATE_SUFFIX) {
527
+ if (getSuffix(name) === PREDICATE_SUFFIX) {
528
528
  throw new TypeError(
529
529
  `Optimized (lambda) ${name} can't be a (Predicate) as it will return a (lambda). Remove the (${PREDICATE_SUFFIX}) from the name`
530
530
  )
@@ -625,7 +625,7 @@ export const deSuggarAst = (ast, scope) => {
625
625
  ]
626
626
  deSuggarAst(exp[exp.length - 1])
627
627
  } else if (prefix === OPTIMIZATIONS.CACHE) {
628
- if (name[name.length - 1] === PREDICATE_SUFFIX) {
628
+ if (getSuffix(name) === PREDICATE_SUFFIX) {
629
629
  throw new TypeError(
630
630
  `Optimized (lambda) ${name} can't be a (Predicate) as it will return a (lambda). Remove the (${PREDICATE_SUFFIX}) from the name`
631
631
  )
package/src/parser.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { APPLY, ATOM, TYPE, WORD, VALUE } from './keywords.js'
2
2
  export const leaf = (type, value) => [type, value]
3
3
  export const isLeaf = ([car]) => car === APPLY || car === ATOM || car === WORD
4
- export const toPair = (exp) => []
5
4
  export const LISP = {
6
5
  parse: (source) => {
7
6
  const tree = []
@@ -30,14 +29,13 @@ export const LISP = {
30
29
  return tree
31
30
  },
32
31
  stringify: (array) => {
33
- if (array == undefined) return '()'
34
- else if (typeof array === 'function') return '(lambda)'
32
+ if (typeof array === 'function') return '(lambda)'
35
33
  else if (typeof array === 'boolean') return +array
36
34
  else if (typeof array === 'object')
37
35
  if (Array.isArray(array))
38
36
  return array.length
39
37
  ? `(array ${array.map(LISP.stringify).join(' ')})`
40
- : '()'
38
+ : '(array)'
41
39
  else
42
40
  return `(array ${array
43
41
  .map(([key, value]) => `("${key}" ${LISP.stringify(value)})`)
@@ -48,7 +46,6 @@ export const LISP = {
48
46
  const dfs = (exp) => {
49
47
  let out = ''
50
48
  const [head, ...tail] = isLeaf(exp) ? [exp] : exp
51
- if (head == undefined) return (out += '(array)')
52
49
  switch (head[TYPE]) {
53
50
  case WORD:
54
51
  out += head[VALUE]
@@ -110,9 +107,6 @@ export const AST = {
110
107
  const dfs = (exp) => {
111
108
  let out = ''
112
109
  const [head, ...tail] = isLeaf(exp) ? [exp] : exp
113
- if (head == undefined)
114
- return (out +=
115
- '(Expression::Apply(vec![Expression::Word("array".to_string())]))')
116
110
  switch (head[TYPE]) {
117
111
  case WORD:
118
112
  out += `Expression::Word("${head[VALUE]}".to_string())`
package/src/utils.js CHANGED
@@ -19,6 +19,7 @@ export const formatCallstack = (callstack) =>
19
19
  export const formatErrorWithCallstack = (error, callstack) => {
20
20
  return `${error.message}\n${formatCallstack(callstack)}`
21
21
  }
22
+ export const getSuffix = (str) => str[str.length - 1]
22
23
  export const removeNoCode = (source) =>
23
24
  source
24
25
  .replace(/(;.+|;)/g, '')