Adding collect function

- Collect function as fn:(collector, x) -> new_collector for collections
- Moving some definitions to "libs" folder
- Map and filter defined in mal
This commit is contained in:
teo3300
2024-06-19 15:51:20 +09:00
parent 35716afee9
commit c5406458de
8 changed files with 80 additions and 44 deletions

23
libs/math.mal Normal file
View File

@ -0,0 +1,23 @@
(def! abs (fn* [a]
(if (> a 0)
a
(- 0 a))))
(def! mod (fn* [a b]
(- a (* (/ a b) b))))
(def! max (fn* [a b]
(if (> a b)
a
b)))
(def! min (fn* [a b]
(if (< a b)
a
b)))
(def! fact (fn* [a]
(def! fact-r (fn* [a b]
(if (not (> a 1)) b
(fact-r (- a 1) (* a b)))))
(fact-r a 1)))