fez-lisp 1.5.49 → 1.5.51

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
@@ -1,82 +1,9 @@
1
- # Fez [Lisp Evaluator in JavaScript](https://medium.com/@antony.k.tonev/lisp-evaluator-in-javascript-b7ee0d817a58)
1
+ # Fez Programming Language
2
2
 
3
3
  <p align="center">
4
- <img width="64" src="./logo.svg"/>
4
+ <img width="128" 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
-
42
- ```js
43
- import { parse, evaluate } from 'fez-lisp'
44
- evaluate(
45
- parse(`(let *input* "1721,979,366,299,675,1456")
46
- (let solve (lambda arr cb
47
- (array:fold arr (lambda a b (do
48
- (let res (array:binary-search arr (cb b)))
49
- (if (truthy? res) (array:merge a (array res)) a)))
50
- ())))
51
- (|> *input*
52
- (string:commas)
53
- (array:map (lambda d (|> d (from:chars->digits) (from:digits->integer))))
54
- (array:sort (lambda a b (> a b)))
55
- (solve (lambda x (- 2020 x)))
56
- (math:product)
57
- (log))`)
58
- )
59
- ```
60
-
61
- ```lisp
62
- ; https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/description/
63
- (let max-count-of (lambda nums
64
- (math:max
65
- (array:count-of nums math:positive?)
66
- (array:count-of nums math:negative?))))
67
-
68
- (|>
69
- (array -2 -1 -1 0 0 1 2)
70
- (max-count-of)
71
- (log!)) ; 3
72
- ```
73
-
74
- Installation:
75
-
76
- ```
77
- npm i fez-lisp
78
- ```
79
-
80
7
  ```lisp
81
8
  (let fizz-buzz (lambda n
82
9
  (cond
@@ -85,23 +12,28 @@ npm i fez-lisp
85
12
  (= (mod n 5) 0) "Buzz"
86
13
  (*) (from:integer->string n))))
87
14
 
88
- (|> (math:range 1 100) (array:map fizz-buzz) (array:commas) (log "str"))
15
+ (|> (math:range 1 100) (array:map fizz-buzz) (array:spaces) (string))
89
16
  ```
90
17
 
91
- ```js
92
- import { parse, compile } from 'fez-lisp'
93
- console.log(compile(parse("(+ 1 2)")))
94
- // '(()=>{;return(()=>{return (1+2);})()})()'
95
- console.log(compile(parse("(math:power 2 4)")))
96
- // (()=>{;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));})()})()
97
- console.log(compile(parse("(|> [1 2 3 4] (array:map math:square) (math:summation))")))
98
- /* (()=>{var __tco=fn=>(...args)=>{let result=fn(...args);while(typeof result==='function')result=result();return result},length=(arr)=>arr.length,alter_effect=function(array,index,value){if(arguments.length===1){array.pop()}else{array[index] = value};return array},get=(arr,i)=>arr[i];
99
- ;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),alter_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)));})()})() * /
100
- ```
18
+ ## [Try it in online editor](https://at-290690.github.io/fez/)
101
19
 
102
20
  ```lisp
103
- ; Build-in all keywords
21
+ ; Build-in keywords
104
22
  (/ ...) (+ ...) (* ...) (- ...) (= ...) (< ...) (> ...) (>= ...) (<= ...) (& ...) (~ ...) (| ...) (^ ...) (<< ...) (>> ...)
105
23
  (mod ...) (let ...) (if ...) (not ...) (and ...) (or ...) (atom? ...) (lambda? ...)
106
24
  (length ...) (do ...) (array ...) (set! ...) (pop! ...) (get ...) (lambda ...) (apply ...) (throw ...)
107
25
  ```
26
+
27
+ ## ⚠️ Important: Do not use this programming language in production!
28
+
29
+ Here is how to install the compiler:
30
+
31
+ ```
32
+ npm i fez-lisp
33
+ ```
34
+
35
+ ```js
36
+ import { parse, compile } from 'fez-lisp'
37
+ console.log(compile(parse('(+ 1 2)')))
38
+ // '(()=>{;return(()=>{return (1+2);})()})()'
39
+ ```
package/favicon.svg ADDED
@@ -0,0 +1,5 @@
1
+ <svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M12.9624 3.54516C12.5818 1.96655 1.39379 2.36647 0.792468 3.54516C0.191149 4.72386 0.792468 15.7151 0.792468 15.7151L12.9624 15.7151C12.9624 15.7151 13.3431 5.12378 12.9624 3.54516Z" fill="#B44637"/>
3
+ <path d="M12.9624 3.54516C12.5818 1.96655 1.39379 2.36647 0.792468 3.54516C0.191149 4.72386 0.792468 15.7151 0.792468 15.7151L12.9624 15.7151C12.9624 15.7151 13.3431 5.12378 12.9624 3.54516Z" fill="#B44637"/>
4
+ <path d="M14.9574 10.9932C11.603 9.9267 16.5755 1.79352 10 1.97363" stroke="#F9B949" stroke-width="2" stroke-linecap="round"/>
5
+ </svg>