aboutsummaryrefslogtreecommitdiffstats
path: root/examples/test.lisp
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2022-09-24 19:23:40 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-05 14:21:53 +0200
commit4e94267a9f97865ebeb19bcbe4945322dd74a1b3 (patch)
tree7653e66e330b64818c3fe364bbadcaa73722c866 /examples/test.lisp
parentdcf52a44f8341b512b18265b3a308d10370ee4ff (diff)
Add nice example code in test.lisp
Diffstat (limited to 'examples/test.lisp')
-rw-r--r--examples/test.lisp56
1 files changed, 30 insertions, 26 deletions
diff --git a/examples/test.lisp b/examples/test.lisp
index 9930181..6608fae 100644
--- a/examples/test.lisp
+++ b/examples/test.lisp
@@ -1,30 +1,9 @@
-;; (let map (\[f lst]
-;; (match lst
-;; [] []
-;; (prepend (f (head lst)) (map f (tail lst))))))
-
-;; (map (+ 1) [1 2 3])
-
-;; (let mapinc (\[vec]
-;; (match vec
-;; [] []
-;; (prepend
-;; (+ 1 (head vec))
-;; (mapinc (tail vec))))))
-;; (env)
-;; (mapinc [1 2 3])
-
-;; (let fibo (\[n]
-;; ;; (let fibo-1 (\[] (fibo (sub2 n 1))))
-;; ;; (let fibo-2 (\[] (fibo (sub2 n 2))))
-;; (match n
-;; 0 0
-;; 1 1
-;; (+
-;; (fibo (- n 1))
-;; (fibo (- n 2))))))
+(let map (\[f lst]
+ (match lst
+ [] []
+ (prepend (f (head lst)) (map f (tail lst))))))
-;; (fibo 10)
+(map (+ 1) [1 2 3])
(let foldr (\[f accumulator lst]
(match lst
@@ -32,3 +11,28 @@
(f (foldr f accumulator (tail lst)) (head lst)))))
(foldr + 0 [1 2 3])
+
+(let filter (\[pred lst]
+ (match lst
+ [] []
+ (match (pred (head lst))
+ true (prepend (head lst) (filter pred (tail lst)))
+ false (filter pred (tail lst))))))
+
+(let pred (\[n]
+ (match n
+ 2 true
+ 4 true
+ false)))
+
+(filter pred [0 1 2 3 4 5])
+
+(let fibo (\[n]
+ (match n
+ 0 0
+ 1 1
+ (+
+ (fibo (- n 1))
+ (fibo (- n 2))))))
+
+(fibo 10)