blob: e2678fb846de6ad5a2977de5a53f7fb8924af839 (
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
|
; identity function
(func . (x) x)
; math
(func ++ (num) (+ num 1))
(func -- (num) (- num 1))
; 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 slice (lst idx)
; TODO doesn't handle lengths
(if (eq? 1 idx)
lst
(slice (rest lst) (- idx 1))))
|