fez-lisp 1.0.7 → 1.0.8
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 +18 -18
- package/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/compiler.js +14 -0
- package/src/enums.js +2 -0
- package/src/interpreter.js +3 -3
- package/src/parser.js +2 -1
- package/src/tokeniser.js +208 -119
- package/src/utils.js +5 -5
package/README.md
CHANGED
@@ -13,8 +13,8 @@
|
|
13
13
|
(*) n)))
|
14
14
|
|
15
15
|
(pi
|
16
|
-
(math
|
17
|
-
(array
|
16
|
+
(math:range 1 100)
|
17
|
+
(array:map fizz-buzz)
|
18
18
|
(log!))
|
19
19
|
```
|
20
20
|
|
@@ -29,26 +29,26 @@
|
|
29
29
|
1456")
|
30
30
|
; solve part 1
|
31
31
|
(let solve (lambda arr cb
|
32
|
-
(array
|
33
|
-
(let res (array
|
32
|
+
(array:fold arr (lambda a b (do
|
33
|
+
(let res (array:binary-search arr (cb b)))
|
34
34
|
(if res (merge a (array res)) a)))
|
35
35
|
())))
|
36
36
|
; 514579
|
37
37
|
(pi *input*
|
38
|
-
(string
|
39
|
-
(cast
|
40
|
-
(array
|
38
|
+
(string:split "\n")
|
39
|
+
(cast:strings->numbers)
|
40
|
+
(array:sort (lambda a b (> a b)))
|
41
41
|
(solve (lambda x (- 2020 x)))
|
42
|
-
(math
|
42
|
+
(math:product)
|
43
43
|
(log!))
|
44
44
|
```
|
45
45
|
|
46
46
|
```lisp
|
47
47
|
; https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/description/
|
48
48
|
(let max-count-of (lambda nums
|
49
|
-
(math
|
50
|
-
(array
|
51
|
-
(array
|
49
|
+
(math:max
|
50
|
+
(array:count-of nums math:positive?)
|
51
|
+
(array:count-of nums math:negative?))))
|
52
52
|
|
53
53
|
(pi
|
54
54
|
(array -2 -1 -1 0 0 1 2)
|
@@ -59,12 +59,12 @@
|
|
59
59
|
```lisp
|
60
60
|
; remove duplicate elements in the arr
|
61
61
|
(let unique (lambda arr (pi
|
62
|
-
(let sorted (array
|
63
|
-
(array
|
64
|
-
(array
|
62
|
+
(let sorted (array:sort arr (safety lambda a b (> a b))))
|
63
|
+
(array:zip (math:sequence sorted))
|
64
|
+
(array:select (lambda x
|
65
65
|
(or (not (let index (car (cdr x))))
|
66
66
|
(not (= (get sorted (- index 1)) (get sorted index))))))
|
67
|
-
(array
|
67
|
+
(array:map car))))
|
68
68
|
; tests
|
69
69
|
(assert
|
70
70
|
(case "test 1" (unique (array 1)) (array 1))
|
@@ -95,8 +95,8 @@ import { fez } from 'fez-lisp'
|
|
95
95
|
eval(
|
96
96
|
fez(
|
97
97
|
`(pi
|
98
|
-
(math
|
99
|
-
(array
|
98
|
+
(math:range 1 11)
|
99
|
+
(array:map (lambda x (* x x)))
|
100
100
|
(log!)))`,
|
101
101
|
// include standard library
|
102
102
|
// compile fez to JavaScript
|
@@ -116,7 +116,7 @@ fez(
|
|
116
116
|
(= (mod n 5) 0) "Buzz"
|
117
117
|
(*) n)))
|
118
118
|
|
119
|
-
(pi (math
|
119
|
+
(pi (math:range 1 100) (array:map fizz-buzz) (log!))`,
|
120
120
|
{ std: true, errors: true, compile: false, shake: true }
|
121
121
|
)
|
122
122
|
```
|