-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcase_macro.scm
57 lines (44 loc) · 1.14 KB
/
tcase_macro.scm
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))))) ;should be ()
(map (lambda (x) (* x 3))
'(2 3 4 5)) ;should be (6 9 12 15)
(define (cadr lst)
(car (cdr lst))) ;should be ()
(defmacro (let args #!rest body)
`((lambda ,(map car args)
,@body)
,@(map cadr args))) ;should be ()
(define body
'(let ((x -3)) (+ 2 x))) ;should be ()
(eval body) ;should be -1
(macroexpand body) ;shoud be ((lambda (x) (+ 2 x)) -3)
(define (caar lst)
(car (car lst))) ;should be ()
(define (cdar lst)
(cdr (car lst))) ;should be ()
(defmacro (cond #!rest conds)
(if (null? conds)
'()
(if (eq? (caar conds) 'else)
`(begin ,@(cdar conds))
`(if ,(caar conds)
(begin ,@(cdar conds))
(cond ,@(cdr conds))))));should be ()
(define x 20) ;should be ()
(define body2
'(cond ((= x 10) #t)
((eq? x 's) #f)
(else
200))) ;should be ()
(eval body2) ;should be 200
(defmacro (and e1 #!rest rest)
`(if (null? (list ,@rest))
,e1
(if ,e1
(and ,@rest)
,e1))) ;should be ()
(and 1 2 3) ;should be 3