fez-lisp 1.3.9 → 1.3.10
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/README.md +1 -64
- package/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/evaluator.js +0 -2
- package/src/parser.js +138 -138
- package/src/utils.js +29 -46
package/README.md
CHANGED
@@ -76,7 +76,7 @@ World
|
|
76
76
|
(let solve (lambda arr cb
|
77
77
|
(array:fold arr (lambda a b (do
|
78
78
|
(let res (array:binary-search arr (cb b)))
|
79
|
-
(if res (array:merge a (array res)) a)))
|
79
|
+
(if (truthy? res) (array:merge a (array res)) a)))
|
80
80
|
())))
|
81
81
|
(|> *input*
|
82
82
|
(string:commas)
|
@@ -190,69 +190,6 @@ Many logical operators
|
|
190
190
|
(= (logic-a 1 2) (logic-b 1 2)))
|
191
191
|
```
|
192
192
|
|
193
|
-
Tail Call Optimization:
|
194
|
-
|
195
|
-
There are no loop constructs (like a "for" or "while" loop in other languages).
|
196
|
-
That's because we don't quite need one: looping in fez is done by recursion — and the interpreter already supports that.
|
197
|
-
But because each procedure call calls evaluate, recursing over a large number of items blows up the call stack of the interpreter.
|
198
|
-
|
199
|
-
This optimization technique works only by declaring the variable with let\*
|
200
|
-
and only when compiled to JavaScript.
|
201
|
-
|
202
|
-
```lisp
|
203
|
-
(let recursive:sum-to (lambda n acc (if (= n 0) acc (recursive:sum-to (- n 1) (+ n acc)))))
|
204
|
-
(recursive:sum-to 10000 0)
|
205
|
-
```
|
206
|
-
|
207
|
-
```js
|
208
|
-
console.log(
|
209
|
-
eval(
|
210
|
-
fez(
|
211
|
-
`(let recursive:sum-to (lambda n acc (if (= n 0) acc (recursive:sum-to (- n 1) (+ n acc)))))
|
212
|
-
(recursive:sum-to 10000 0)`,
|
213
|
-
{ compile: 1 }
|
214
|
-
)
|
215
|
-
)
|
216
|
-
)
|
217
|
-
// 50005000
|
218
|
-
```
|
219
|
-
|
220
|
-
Pass tree source as text:
|
221
|
-
|
222
|
-
```js
|
223
|
-
import { fez } from '../index.js'
|
224
|
-
const source = `(|>
|
225
|
-
(array 1 2 3 4)
|
226
|
-
(math:permutations)
|
227
|
-
(array:flat-one)
|
228
|
-
(math:summation)
|
229
|
-
(log!))`
|
230
|
-
fez(source, {
|
231
|
-
mutation: 1
|
232
|
-
})
|
233
|
-
```
|
234
|
-
|
235
|
-
Pass tree instead of a source:
|
236
|
-
|
237
|
-
```js
|
238
|
-
import { fez, tree, std } from '../index.js'
|
239
|
-
const source = `(|>
|
240
|
-
(array 1 2 3 4)
|
241
|
-
(math:permutations)
|
242
|
-
(array:flat-one)
|
243
|
-
(math:summation)
|
244
|
-
(log!))`
|
245
|
-
const ast = tree(source, std)
|
246
|
-
fez(ast, { mutation: 1 })
|
247
|
-
```
|
248
|
-
|
249
|
-
If passing AST and STD is not used then use tree with a single arugment
|
250
|
-
|
251
|
-
```js
|
252
|
-
import { fez, tree } from '../index.js'
|
253
|
-
console.log(fez(tree(`(+ (|> 1 (+ 2) (* 3) (- 1)) (- (* (+ 1 2) 3) 1))`)))
|
254
|
-
```
|
255
|
-
|
256
193
|
```lisp
|
257
194
|
; Build-in all keywords
|
258
195
|
(/ ...) (+ ...) (* ...) (- ...) (= ...) (< ...) (> ...) (>= ...) (<= ...) (& ...) (~ ...) (| ...) (^ ...) (<< ...) (>> ...) (>>> ...)
|