-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice-1.scm
77 lines (48 loc) · 1.79 KB
/
practice-1.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;; SICP Practice: 1
(define self-cons
(lambda (x y)
(lambda (z) (z x y))))
(define self-cdr
(lambda (z)
(z (lambda (p q) q))))
(self-cdr (self-cons 1 2))
;; Step of eval/apply:
;; => e0 <TOP> : cons car apply eval bind
;; (eval '(cdr (cons 1 2) e0))
;; (apply (eval 'cdr e0)
;; (ev-list '((cons 1 2)) e0))
;; (apply '(closure ((z) (z (lambda (p q) q))) e0)
;; (list (eval '(cons 1 2) e0)))
;; (apply '(closure ((z) (z (lambda (p q) q))) e0)
;; (list (apply (eval 'cons e0)
;; (ev-list '((1 2)) e0))))
;; (apply '(closure ((z) (z (lambda (p q) q))) e0)
;; (list (apply (eval 'cons e0)
;; '(1 2))))
;; (apply '(closure ((z) (z (lambda (p q) q))) e0)
;; (list (apply '(closure ((x y) (lambda (z) (z x y))) e0)
;; '(1 2))))
;; (apply '(closure ((z) (z (lambda (p q) q))) e0)
;; (list (eval '(lambda (z) (z x y)) (bind '((x 1) (y 2)) e0))))
;; => e1 <e0> : x = 1; y = 2
;; (apply '(closure ((z) (z (lambda (p q) q))) e0)
;; (list '(closure ((z) (z x y)) e1)))
;; (apply '(closure ((z) (z (lambda (p q) q))) e0)
;; '((closure ((z) (z x y)) e1)))
;; (eval '(z (lambda (p q) q)) (bind '((z (closure ((z) (z x y)) e1))) e0))
;; => e2 <e0> : z = (closure ((z) (z x y)) e1)
;; (apply (eval 'z e2)
;; (ev-list '((lambda (p q) q)) e2))
;; (apply '(closure ((z) (z x y)) e1)
;; (eval '(lambda (p q) q) e2))
;; (apply '(closure ((z) (z x y)) e1)
;; '(closure ((p q) q) e2))
;; (eval '(z x y) (bind '((z (closure ((p q) q) e2))) e1))
;; => e3 <e1> : z = (closure ((p q) q) e2)
;; (apply (eval 'z e3)
;; (ev-list '(x y) e3))
;; (apply '(closure ((p q) q) e2)
;; '(1 2))
;; (eval 'q (bind '((p 1) (q 2)) e2))
;; => e4 <e2> : p = 1; q = 2
;; 2