fez-lisp 1.0.54 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -4,9 +4,7 @@
4
4
  <img width="64" src="./logo.svg"/>
5
5
  </p>
6
6
 
7
-
8
-
9
- ```lisp
7
+ ````lisp
10
8
  (let fizz-buzz (lambda n
11
9
  (cond
12
10
  (= (mod n 15) 0) "Fizz Buzz"
@@ -14,21 +12,39 @@
14
12
  (= (mod n 5) 0) "Buzz"
15
13
  (*) n)))
16
14
 
15
+ (|>
16
+ (math:range 1 100)
17
+ (array:map fizz-buzz)
18
+ (log!))
19
+ ```
20
+
21
+ ```lisp
22
+ (let Fizz (string char:F char:i char:z char:z))
23
+ (let Buzz (string char:B char:u char:z char:z))
24
+ (let FizzBuzz (string Fizz Buzz))
25
+
26
+ (let fizz-buzz (lambda n
27
+ (cond
28
+ (= (mod n 15) 0) FizzBuzz
29
+ (= (mod n 3) 0) Fizz
30
+ (= (mod n 5) 0) Buzz
31
+ (*) n)))
32
+
17
33
  (|>
18
34
  (math:range 1 100)
19
35
  (array:map fizz-buzz)
20
36
  (log!))
21
- ```
37
+ ````
22
38
 
23
39
  ```lisp
24
40
  ; https://adventofcode.com/2020/day/1
25
41
  (let *input*
26
- "1721
27
- 979
28
- 366
29
- 299
30
- 675
31
- 1456")
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))
32
48
  ; solve part 1
33
49
  (let solve (lambda arr cb
34
50
  (array:fold arr (lambda a b (do
@@ -37,8 +53,24 @@
37
53
  ())))
38
54
  ; 514579
39
55
  (|> *input*
40
- (string:split "\n")
41
- (cast:strings->numbers)
56
+ (string:lines)
57
+ (array:map (lambda d (|> d (cast:chars->digits) (cast:digits->number))))
58
+ (array:sort (lambda a b (> a b)))
59
+ (solve (lambda x (- 2020 x)))
60
+ (math:product)
61
+ (log!))
62
+ ```
63
+
64
+ ```lisp
65
+ (let *input* "1721,979,366,299,675,1456")
66
+ (let solve (lambda arr cb
67
+ (array:fold arr (lambda a b (do
68
+ (let res (array:binary-search arr (cb b)))
69
+ (if res (cons a (array res)) a)))
70
+ ())))
71
+ (|> *input*
72
+ (string:commas)
73
+ (array:map (lambda d (|> d (cast:chars->digits) (cast:digits->number))))
42
74
  (array:sort (lambda a b (> a b)))
43
75
  (solve (lambda x (- 2020 x)))
44
76
  (math:product)
@@ -69,8 +101,8 @@
69
101
  (array:map car))))
70
102
  ; tests
71
103
  (assert
72
- (case "test 1" (unique (array 1)) (array 1))
73
- (case "test 2" (unique (array 1 2 2 4 5 9 5 12 14 1)) (array 1 2 4 5 9 12 14)))
104
+ (case (unique (array 1)) (array 1))
105
+ (case (unique (array 1 2 2 4 5 9 5 12 14 1)) (array 1 2 4 5 9 12 14)))
74
106
  ```
75
107
 
76
108
  Installation:
@@ -81,12 +113,12 @@ npm i fez-lisp
81
113
 
82
114
  ```js
83
115
  import { fez } from 'fez-lisp'
84
- fez(`(log! "Hello World!")`) // Hello World!
116
+ fez(`(log! "Hello World!")`, { strings: true }) // Hello World!
85
117
  ```
86
118
 
87
119
  ```js
88
120
  import { fez } from 'fez-lisp'
89
- fez(`(+ 1 "2")`) // Not all arguments of (+) are (number) (+ 1 2)
121
+ fez(`(+ 1 (array 2))`) // Not all arguments of (+) are (number) (+ 1 (array 2))
90
122
  ```
91
123
 
92
124
  ```js
@@ -100,7 +132,7 @@ eval(
100
132
  // include standard library
101
133
  // compile fez to JavaScript
102
134
  // tree shake standard library
103
- { std: true, compile: true }
135
+ { compile: true }
104
136
  )
105
137
  )
106
138
  ```
@@ -108,15 +140,20 @@ eval(
108
140
  ```js
109
141
  import { fez } from 'fez-lisp'
110
142
  fez(
111
- `(let fizz-buzz (lambda n
143
+ `
144
+ (let Fizz (string char:F char:i char:z char:z))
145
+ (let Buzz (string char:B char:u char:z char:z))
146
+ (let FizzBuzz (string Fizz Buzz))
147
+
148
+ (let fizz-buzz (lambda n
112
149
  (cond
113
- (= (mod n 15) 0) "Fizz Buzz"
114
- (= (mod n 3) 0) "Fizz"
115
- (= (mod n 5) 0) "Buzz"
150
+ (= (mod n 15) 0) FizzBuzz
151
+ (= (mod n 3) 0) Fizz
152
+ (= (mod n 5) 0) Buzz
116
153
  (*) n)))
117
154
 
118
155
  (|> (math:range 1 100) (array:map fizz-buzz) (log!))`,
119
- { std: true, compile: false }
156
+ { compile: false }
120
157
  )
121
158
  ```
122
159
 
@@ -124,8 +161,8 @@ Many logical operators
124
161
 
125
162
  ```lisp
126
163
  (let logic-a (lambda a b
127
- (if (or (= b -1) (> a b)) "a"
128
- (if (and (> b 2) (< a 4)) "b" "c"))))
164
+ (if (or (= b -1) (> a b)) char:a
165
+ (if (and (> b 2) (< a 4)) char:b char:c))))
129
166
 
130
167
  ; De Morgan's First Law: ¬(P ∧ Q) is equivalent to (¬P ∨ ¬Q)
131
168
  ; De Morgan's Second Law: ¬(P ∨ Q) is equivalent to (¬P ∧ ¬Q)
@@ -133,13 +170,13 @@ Many logical operators
133
170
  ; Swapping the consequent with the alternative in the condition by using (unless) instead of (if)
134
171
  ; The condition (or (= b -1) (> a b)) has been changed to (and (not (= b -1)) (not (> a b))), applying De Morgan's First Law.
135
172
  ; The condition (and (> b 2) (< a 4)) has been changed to (or (not (> b 2)) (not (< a 4))), applying De Morgan's Second Law.
136
- (unless (and (not (= b -1)) (not (> a b))) "a"
137
- (unless (or (not (> b 2)) (not (< a 4))) "b" "c"))))
173
+ (unless (and (not (= b -1)) (not (> a b))) char:a
174
+ (unless (or (not (> b 2)) (not (< a 4))) char:b char:c))))
138
175
 
139
176
  (assert
140
- (case "a=0 b=-1" (logic-a 0 -1) (logic-b 0 -1))
141
- (case "a=1 b=3" (logic-a 1 3) (logic-b 1 3))
142
- (case "a=1 b=2" (logic-a 1 2) (logic-b 1 2)))
177
+ (case (logic-a 0 -1) (logic-b 0 -1))
178
+ (case (logic-a 1 3) (logic-b 1 3))
179
+ (case (logic-a 1 2) (logic-b 1 2)))
143
180
  ```
144
181
 
145
182
  Tail Call Optimization:
@@ -178,7 +215,6 @@ const source = `(|>
178
215
  (math:summation)
179
216
  (log!))`
180
217
  fez(source, {
181
- std: 1,
182
218
  mutation: 1
183
219
  })
184
220
  ```