fez-lisp 1.3.27 → 1.4.0

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 CHANGED
@@ -16,7 +16,7 @@
16
16
  (let arr (array 1 2 3))
17
17
  (set! arr 0 10)
18
18
  (set! arr (length arr) 100)
19
- ; arr is now will make it '(10 2 3 100)
19
+ ; arr is now will make it [10 2 3 100]
20
20
  ; No strings - instead they are array of charcodes
21
21
  "Hello World!" ; This is syntactic suggar turning it into the one below
22
22
  (array 72 101 108 108 111 32 87 111 114 108 100 33) ; "Hello World!"
@@ -39,40 +39,10 @@ World
39
39
  (|> (math:range 1 10) (array:map math:square) (math:summation))
40
40
  ```
41
41
 
42
- ```lisp
43
- (let fizz-buzz (lambda n
44
- (cond
45
- (= (mod n 15) 0) "Fizz Buzz"
46
- (= (mod n 3) 0) "Fizz"
47
- (= (mod n 5) 0) "Buzz"
48
- (*) n)))
49
-
50
- (|>
51
- (math:range 1 100)
52
- (array:map fizz-buzz)
53
- (log!))
54
- ```
55
-
56
- ```lisp
57
- (let Fizz (array char:F char:i char:z char:z))
58
- (let Buzz (array char:B char:u char:z char:z))
59
- (let FizzBuzz (array Fizz Buzz))
60
-
61
- (let fizz-buzz (lambda n
62
- (cond
63
- (= (mod n 15) 0) FizzBuzz
64
- (= (mod n 3) 0) Fizz
65
- (= (mod n 5) 0) Buzz
66
- (*) n)))
67
-
68
- (|>
69
- (math:range 1 100)
70
- (array:map fizz-buzz)
71
- (log!))
72
- ```
73
-
74
- ```lisp
75
- (let *input* "1721,979,366,299,675,1456")
42
+ ```js
43
+ import { parse, debug } from 'fez-lisp'
44
+ debug(
45
+ parse(`(let *input* "1721,979,366,299,675,1456")
76
46
  (let solve (lambda arr cb
77
47
  (array:fold arr (lambda a b (do
78
48
  (let res (array:binary-search arr (cb b)))
@@ -84,7 +54,8 @@ World
84
54
  (array:sort (lambda a b (> a b)))
85
55
  (solve (lambda x (- 2020 x)))
86
56
  (math:product)
87
- (log!))
57
+ (log))`)
58
+ )
88
59
  ```
89
60
 
90
61
  ```lisp
@@ -100,22 +71,6 @@ World
100
71
  (log!)) ; 3
101
72
  ```
102
73
 
103
- ```lisp
104
- ; remove duplicate elements in the arr
105
- (let unique (lambda arr (|>
106
- (let sorted (array:sort arr (lambda a b (> a b))))
107
- (array:zip (math:sequence sorted))
108
- (array:select (lambda x (do
109
- (let index (car (cdr x)))
110
- (or (not (> index 0))
111
- (not (= (array:get sorted (- index 1)) (array:get sorted index)))))))
112
- (array:map car))))
113
- ; tests
114
- (and
115
- (array:equal? (unique (array 1)) (array 1))
116
- (array:equal? (unique (array 1 2 2 4 5 9 5 12 14 1)) (array 1 2 4 5 9 12 14)))
117
- ```
118
-
119
74
  Installation:
120
75
 
121
76
  ```
@@ -123,71 +78,38 @@ npm i fez-lisp
123
78
  ```
124
79
 
125
80
  ```js
126
- import { fez } from 'fez-lisp'
127
- fez(`(log! "Hello World!")`) // Hello World!
81
+ import { parse, debug } from 'fez-lisp'
82
+ debug(parse(`(log "Hello World!" "str")`)) // Hello World!
128
83
  ```
129
84
 
130
85
  ```js
131
- import { fez } from 'fez-lisp'
132
- fez(`(+ 1 (array 2))`) // Not all arguments of (+) are (number) (+ 1 (array 2))
86
+ import { parse, debug } from 'fez-lisp'
87
+ debug(parse(`(+ 1 (array 2))`)) // TypeError: Second arguments of (+) is not a (number) at: (+ 1 (array 2) scope: (apply)
133
88
  ```
134
89
 
135
- ```js
136
- import { fez } from 'fez-lisp'
137
- eval(
138
- fez(
139
- `(|>
140
- (math:range 1 11)
141
- (array:map (lambda x (* x x)))
142
- (log!)))`,
143
- // include standard library
144
- // compile fez to JavaScript
145
- // tree shake standard library
146
- { compile: true }
147
- )
148
- )
149
- ```
90
+ ````js
150
91
 
151
- ```js
152
- import { fez } from 'fez-lisp'
153
- fez(
154
- `
155
- (let Fizz (array char:F char:i char:z char:z))
156
- (let Buzz (array char:B char:u char:z char:z))
157
- (let FizzBuzz (array Fizz Buzz))
158
-
159
- (let fizz-buzz (lambda n
160
- (cond
161
- (= (mod n 15) 0) FizzBuzz
162
- (= (mod n 3) 0) Fizz
163
- (= (mod n 5) 0) Buzz
164
- (*) n)))
165
-
166
- (|> (math:range 1 100) (array:map fizz-buzz) (log!))`,
167
- { compile: false }
168
- )
169
- ```
170
-
171
- Many logical operators
172
92
 
173
93
  ```lisp
174
- (let logic-a (lambda a b
175
- (if (or (= b -1) (> a b)) char:a
176
- (if (and (> b 2) (< a 4)) char:b char:c))))
94
+ (let fizz-buzz (lambda n
95
+ (cond
96
+ (= (mod n 15) 0) "FizzBuzz"
97
+ (= (mod n 3) 0) "Fizz"
98
+ (= (mod n 5) 0) "Buzz"
99
+ (*) (from:number->string n))))
177
100
 
178
- ; De Morgan's First Law: ¬(P ∧ Q) is equivalent to (¬P ∨ ¬Q)
179
- ; De Morgan's Second Law: ¬(P ∨ Q) is equivalent to (¬P ∧ ¬Q)
180
- (let logic-b (lambda a b
181
- ; Swapping the consequent with the alternative in the condition by using (unless) instead of (if)
182
- ; The condition (or (= b -1) (> a b)) has been changed to (and (not (= b -1)) (not (> a b))), applying De Morgan's First Law.
183
- ; The condition (and (> b 2) (< a 4)) has been changed to (or (not (> b 2)) (not (< a 4))), applying De Morgan's Second Law.
184
- (unless (and (not (= b -1)) (not (> a b))) char:a
185
- (unless (or (not (> b 2)) (not (< a 4))) char:b char:c))))
101
+ (|> (math:range 1 100) (array:map fizz-buzz) (array:commas) (log "str"))
102
+ ````
186
103
 
187
- (and
188
- (= (logic-a 0 -1) (logic-b 0 -1))
189
- (= (logic-a 1 3) (logic-b 1 3))
190
- (= (logic-a 1 2) (logic-b 1 2)))
104
+ ```js
105
+ import { parse, compile } from 'fez-lisp'
106
+ console.log(compile(parse("(+ 1 2)")))
107
+ // '(()=>{;return(()=>{return (1+2);})()})()'
108
+ console.log(compile(parse("(math:power 2 4)")))
109
+ // (()=>{;return(()=>{var math_power;return (math_power=((base,exp)=>{return (+(exp<0)?(+(base===0)?[]:(1/(base*math_power(base,((exp*-1)-1))))):(+(exp===0)?1:(+(exp===1)?base:(1?(base*math_power(base,(exp-1))):0))));}),math_power(2,4));})()})()
110
+ console.log(compile(parse("(|> [1 2 3 4] (array:map math:square) (math:summation))")))
111
+ /* (()=>{var __tco=fn=>(...args)=>{let result=fn(...args);while(typeof result==='function')result=result();return result},length=(arr)=>arr.length,set_effect=function(array,index,value){if(arguments.length===1){array.pop()}else{array[index] = value};return array},get=(arr,i)=>arr[i];
112
+ ;return(()=>{var math_summation,math_square,array_map,array_fold;return (math_summation=((xs)=>{return array_fold(xs,((a,b)=>{return (a+b);}),0);}),math_square=((x)=>{return (x*x);}),array_map=((xs,callback)=>{var recursive_array_map,recursive_9271675;return ((recursive_array_map=(__tco(recursive_9271675=(i,out)=>{return (+(length(xs)>i)?()=>recursive_9271675((i+1),set_effect(out,length(out),callback(get(xs, i)))):out);}, recursive_9271675))),recursive_array_map(0,[]));}),array_fold=((xs,callback,initial)=>{var recursive_array_fold,recursive_927729;return ((recursive_array_fold=(__tco(recursive_927729=(i,out)=>{return (+(length(xs)>i)?()=>recursive_927729((i+1),callback(out,get(xs, i))):out);}, recursive_927729))),recursive_array_fold(0,initial));}),math_summation(array_map([1,2,3,4],math_square)));})()})() * /
191
113
  ```
192
114
 
193
115
  ```lisp
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { evaluate } from './src/evaluator.js'
2
- import { LISP, AST } from './src/parser.js'
3
- import { fez, prep } from './src/utils.js'
4
- import std from './lib/baked/std.js'
5
- export { fez, evaluate, std, prep, LISP, AST }
2
+ import { compile } from './src/compiler.js'
3
+ import { debug, parse } from './src/utils.js'
4
+ export { parse, evaluate, compile, debug }