-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd.kf
39 lines (33 loc) · 877 Bytes
/
std.kf
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
(def ($len lst) (. lst __len__))
(def ($first lst) (. lst __getitem__ 0))
(def ($second lst) (. lst __getitem__ 1))
(def ($rest lst) (split lst 1))
(def ($empty? lst) (= (len lst) 0))
(def ($cond $bool $expr $...)
; (cond <<bool|"else"> <expr>>)
(let ([else #t])
(if (eval bool)
(eval expr)
(if (not (empty? ...))
(apply cond ...)
))))
(def ($or $...)
(if (empty? ...)
#f
(let ([b (eval (first ...))])
(if b b (apply or (rest ...))))))
(def (not _)
(if _
#f
#t))
(def ($and $...)
(if (empty? ...)
#t
(let ([b (eval (first ...))])
(if b (apply or (rest ...)) b))))
(def (print obj) (printf (concat (. obj __str__) " ")))
(def (println obj)
(do
(printf (. obj __str__))
(printf "\n")
))