-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path4-8.scm
42 lines (41 loc) · 1.31 KB
/
4-8.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
;; named let
(define (named-let-package-install)
(define (let-name let)
(if (symbol? (car let))
(car let)
false))
(define (let-body let)
(if (symbol? (car let))
(caddr let)
(cadr let)))
(define (let-bingdings let)
(if (symbol? (car let))
(cadr let)
(car let)))
(define (let-variables bindings)
(if (null? bindings)
'()
(cons (car (car bindings))
(let-variables (cdr bindings)))))
(define (let-expressions bindings)
(if (null? bindings)
'()
(cons (cadr (car bindings))
(let-expressions (cdr bindings)))))
(define (let->combination let)
(let ((bindings (let-bindings let))
(name (let-name let)))
(if name
(make-begin
(list (make-definition name
(make-lambda (let-variables bindings)
(let-body let)))
(make-call name (let-expressions bindings))))
(make-call (make-lambda (let-variables paras)
(let-body let))
(let-expressions paras)))))
(define (eval-self let env)
(eval (let->combination let) env))
(define (tag x) (attach-tag 'let x))
(put 'let 'eval eval-self)
(put 'let 'make tag))