fez-lisp 1.2.43 → 1.2.45
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 +39 -29
- package/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/compiler.js +38 -10
- package/src/interpreter.js +13 -38
- package/src/keywords.js +3 -1
- package/src/utils.js +4 -3
package/README.md
CHANGED
@@ -4,6 +4,41 @@
|
|
4
4
|
<img width="64" src="./logo.svg"/>
|
5
5
|
</p>
|
6
6
|
|
7
|
+
```lisp
|
8
|
+
; 3 types only
|
9
|
+
; Numbers
|
10
|
+
; Arrays
|
11
|
+
; Functions
|
12
|
+
(do 42 (array 1 2 3) (lambda x (* x x)))
|
13
|
+
; Variables are immutable
|
14
|
+
(let x 42)
|
15
|
+
; But array items are not
|
16
|
+
(let arr (array 1 2 3))
|
17
|
+
(set! arr 0 10)
|
18
|
+
(set! arr (length arr) 100)
|
19
|
+
; arr is now will make it '(10 2 3 100)
|
20
|
+
; No strings - instead they are array of charcodes
|
21
|
+
"Hello World!" ; This is syntactic suggar turning it into the one below
|
22
|
+
(array 72 101 108 108 111 32 87 111 114 108 100 33) ; "Hello World!"
|
23
|
+
; multiline strings support (it just captures whole string and adds new lines within the arrays)
|
24
|
+
"Hello
|
25
|
+
World
|
26
|
+
!"
|
27
|
+
; No Objects Sets Lists Classes etc. Yet all implemented using the 3 types above
|
28
|
+
(let object (new:map
|
29
|
+
(array "id" 16
|
30
|
+
"power" (lambda x (* x x))
|
31
|
+
"backpack" (array 100 100 200 300)
|
32
|
+
"unique-set-of-things"
|
33
|
+
(new:set (array "10" "232" "42" "32")))))
|
34
|
+
(apply (map:get object "power") (map:get object "id")) ; 256
|
35
|
+
; There are many useful functions in the STD library
|
36
|
+
; They get "tree shacked" - final program has only the functions it needs
|
37
|
+
(math:permutations (array 1 2 3))
|
38
|
+
; Pipe operator is syntactic sugar for readable function composition
|
39
|
+
(|> (math:range 1 10) (array:map math:square) (math:summation))
|
40
|
+
```
|
41
|
+
|
7
42
|
```lisp
|
8
43
|
(let fizz-buzz (lambda n
|
9
44
|
(cond
|
@@ -36,31 +71,6 @@
|
|
36
71
|
(log!))
|
37
72
|
```
|
38
73
|
|
39
|
-
```lisp
|
40
|
-
; https://adventofcode.com/2020/day/1
|
41
|
-
(let *input*
|
42
|
-
(string
|
43
|
-
char:1 char:7 char:2 char:1 char:new-line
|
44
|
-
char:3 char:6 char:6 char:new-line
|
45
|
-
char:2 char:9 char:9 char:new-line
|
46
|
-
char:6 char:7 char:5 char:new-line
|
47
|
-
char:1 char:4 char:5 char:6))
|
48
|
-
; solve part 1
|
49
|
-
(let solve (lambda arr cb
|
50
|
-
(array:fold arr (lambda a b (do
|
51
|
-
(let res (array:binary-search arr (cb b)))
|
52
|
-
(if res (array:merge a (array res)) a)))
|
53
|
-
())))
|
54
|
-
; 514579
|
55
|
-
(|> *input*
|
56
|
-
(string:lines)
|
57
|
-
(array:map (lambda d (|> d (from:chars->digits) (from:digits->number))))
|
58
|
-
(array:sort (lambda a b (> a b)))
|
59
|
-
(solve (lambda x (- 2020 x)))
|
60
|
-
(math:product)
|
61
|
-
(log!))
|
62
|
-
```
|
63
|
-
|
64
74
|
```lisp
|
65
75
|
(let *input* "1721,979,366,299,675,1456")
|
66
76
|
(let solve (lambda arr cb
|
@@ -190,15 +200,15 @@ This optimization technique works only by declaring the variable with let\*
|
|
190
200
|
and only when compiled to JavaScript.
|
191
201
|
|
192
202
|
```lisp
|
193
|
-
(let
|
194
|
-
(
|
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)
|
195
205
|
```
|
196
206
|
|
197
207
|
```js
|
198
208
|
console.log(
|
199
209
|
fez(
|
200
|
-
`(let
|
201
|
-
(
|
210
|
+
`(let recursive:sum-to (lambda n acc (if (= n 0) acc (recursive:sum-to (- n 1) (+ n acc)))))
|
211
|
+
(recursive:sum-to 10000 0)`,
|
202
212
|
{ compile: 1, eval: 1 }
|
203
213
|
)
|
204
214
|
)
|