-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ilisp
64 lines (44 loc) · 1.53 KB
/
example.ilisp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(load "standard.ilisp")
(concat "hello" " " "martin") ; hello martin
(unpack + '(1 2 3)) ; 6
(pack head 1 2 3) ; 1
(do
(print "do first")
(print "do second"))
(let '(x) '(100)
'(do
(print x)))
(let '(x) '(1) '(x))
((flip concat) "hi" "world") ; worldhi
(def '(mul-neg) (comp - (unpack *)))
(mul-neg '(2 8)) ; 16
(fst '(1 2 3)) ; 1
(snd '(1 2 3)) ; 2
(trd '(1 2 3)) ; 3
(len '(1 1 1)) ; 3
(nth 0 '(10 20 30 40)) ; 10
(nth 2 '(10 20 30 40)) ; 30
(last '(10 20 30 40)) ; 40
(take 2 '(1 2 3 4)) ; 1 2
(drop 2 '(1 2 3 4)) ; 3 4
(split 3 '(1 2 3 4 5)) ; (1 2 3) (4 5)
(elem 4 '(1 2 3 4 5 99)) ; 1 (true)
(map (fn '(x) '(* x 2)) '(1 2 3)) ; 2 4 6
(filter (fn '(x) '(== x 1)) '(0 1 0 1)) ; 1 1
(foldl + 0 '(1 2 3 4 5)) ; 15
(sum '(1 2 3)) ; 6
(product '(1 2 3 4)) ; 24
(defn '(name-of-num) '(x)
'(select
'((== x 0) "zero")
'((== x 1) "one")
'(true "other")))
(name-of-num 1) ; "two"
(name-of-num 3) ; "other"
(defn '(day-name) '(x)
'(case x
'(0 "Monday")
'(1 "Tuesday")
'(2 "Wednesday")))
(day-name 2) ; Wednesday
(fib 12) ; 144