aboutsummaryrefslogtreecommitdiffstats
path: root/examples/test.lisp
blob: 6608fae52eafdebe5c53e8d015c9cd7088df4082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(let map (\[f lst]
    (match lst
        [] []
        (prepend (f (head lst)) (map f (tail lst))))))

(map (+ 1) [1 2 3])

(let foldr (\[f accumulator lst]
    (match lst
        []  accumulator
        (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)