-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.scm
More file actions
57 lines (48 loc) · 1.1 KB
/
setup.scm
File metadata and controls
57 lines (48 loc) · 1.1 KB
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
(define (map fun lst)
(if (null? lst)
'()
(cons
(fun (car lst))
(map fun (cdr lst)))))
(define (for-each fun lst)
(if (null? lst)
'()
(begin
(fun (car lst))
(for-each fun (cdr lst)))))
(define (cadr lst)
(car (cdr lst)))
(defmacro (let args #!rest body)
`((lambda ,(map car args)
,@body)
,@(map cadr args)))
(define (caar lst)
(car (car lst)))
(define (cdar lst)
(cdr (car lst)))
(defmacro (cond #!rest conds)
(if (null? conds)
'()
(if (eq? (caar conds) 'else)
`(begin ,@(cdar conds))
`(if ,(caar conds)
(begin ,@(cdar conds))
(cond ,@(cdr conds))))))
(defmacro (and e1 #!rest rest)
`(if (null? (list ,@rest))
,e1
(if ,e1
(and ,@rest)
,e1)))
;; this function is not intended used as basic function, but it was need
;; by ->> macro, and we don't support define function in macro body yet
(define (list-if-not x)
(if (list? x)
x
(list x)))
(defmacro (->> x #!rest form)
(if (null? form)
x
`(->> ,(append (list-if-not (car form))
(list x))
,@(cdr form))))