blob: 4bbb63e8f6637c5814bd4f0f7e0d051a644185b3 (
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
39
40
41
42
43
44
45
|
; identity function
(func . (x) x)
; math
(func ++ (num) (+ num 1))
(func -- (num) (- num 1))
(func min (lst)
(reduce
(lambda (acc x)
(if (< x acc)
x
acc))
(rest lst)
(first lst)))
; strings
(func join (lst joiner)
; TODO this doesn't handle empty lists
(concat
(reduce
(lambda (acc x)
(concat acc x joiner))
(most lst)
"")
(last lst)))
(func strip (str)
; TODO need escape codes
(def whitespace (list " " " " "
"))
(branch
((in? (first str) whitespace) (strip (rest str)))
((in? (last str) whitespace) (strip (most str)))
(#true str)))
; lists
(func extend (lst1 lst2)
(reduce append lst2 lst1))
(func slice (lst idx)
; TODO doesn't handle lengths
(if (eq? 1 idx)
lst
(slice (rest lst) (- idx 1))))
|