fez-lisp 1.5.50 → 1.5.52
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 +19 -87
- package/favicon.svg +5 -0
- package/lib/baked/std.js +1 -1
- package/logo.svg +15 -5
- package/package.json +1 -1
- package/src/check.js +42 -140
- package/src/evaluator.js +10 -16
- package/src/interpreter.js +0 -7
- package/src/keywords.js +1 -2
- package/src/macros.js +95 -85
package/README.md
CHANGED
@@ -1,107 +1,39 @@
|
|
1
|
-
# Fez
|
1
|
+
# Fez Programming Language
|
2
2
|
|
3
3
|
<p align="center">
|
4
|
-
<img width="
|
4
|
+
<img width="128" src="./logo.svg"/>
|
5
5
|
</p>
|
6
6
|
|
7
7
|
```lisp
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
(
|
13
|
-
|
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
|
-
```
|
8
|
+
(let fezz-buzz (lambda n
|
9
|
+
(cond
|
10
|
+
(= (mod n 15) 0) "FezzBuzz"
|
11
|
+
(= (mod n 3) 0) "Fezz"
|
12
|
+
(= (mod n 5) 0) "Buzz"
|
13
|
+
(*) (from:integer->string n))))
|
41
14
|
|
42
|
-
|
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
|
-
)
|
15
|
+
(|> (math:range 1 100) (array:map fezz-buzz) (array:spaces) (string))
|
59
16
|
```
|
60
17
|
|
61
|
-
|
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?))))
|
18
|
+
## [Try it in online editor](https://at-290690.github.io/fez/)
|
67
19
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
20
|
+
```lisp
|
21
|
+
; Build-in keywords
|
22
|
+
(/ ...) (+ ...) (* ...) (- ...) (= ...) (< ...) (> ...) (>= ...) (<= ...) (& ...) (~ ...) (| ...) (^ ...) (<< ...) (>> ...)
|
23
|
+
(mod ...) (let ...) (if ...) (not ...) (and ...) (or ...) (atom? ...) (lambda? ...)
|
24
|
+
(length ...) (do ...) (array ...) (set! ...) (pop! ...) (get ...) (lambda ...) (apply ...) (throw ...)
|
72
25
|
```
|
73
26
|
|
74
|
-
|
27
|
+
## ⚠️ Important: Do not use this programming language in production!
|
28
|
+
|
29
|
+
Here is how to install the compiler:
|
75
30
|
|
76
31
|
```
|
77
32
|
npm i fez-lisp
|
78
33
|
```
|
79
34
|
|
80
|
-
```lisp
|
81
|
-
(let fizz-buzz (lambda n
|
82
|
-
(cond
|
83
|
-
(= (mod n 15) 0) "FizzBuzz"
|
84
|
-
(= (mod n 3) 0) "Fizz"
|
85
|
-
(= (mod n 5) 0) "Buzz"
|
86
|
-
(*) (from:integer->string n))))
|
87
|
-
|
88
|
-
(|> (math:range 1 100) (array:map fizz-buzz) (array:commas) (log "str"))
|
89
|
-
```
|
90
|
-
|
91
35
|
```js
|
92
36
|
import { parse, compile } from 'fez-lisp'
|
93
|
-
console.log(compile(parse(
|
37
|
+
console.log(compile(parse('(+ 1 2)')))
|
94
38
|
// '(()=>{;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
|
-
```
|
101
|
-
|
102
|
-
```lisp
|
103
|
-
; Build-in all keywords
|
104
|
-
(/ ...) (+ ...) (* ...) (- ...) (= ...) (< ...) (> ...) (>= ...) (<= ...) (& ...) (~ ...) (| ...) (^ ...) (<< ...) (>> ...)
|
105
|
-
(mod ...) (let ...) (if ...) (not ...) (and ...) (or ...) (atom? ...) (lambda? ...)
|
106
|
-
(length ...) (do ...) (array ...) (set! ...) (pop! ...) (get ...) (lambda ...) (apply ...) (throw ...)
|
107
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>
|