Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (39 sloc) 1.31 KB
(define (let? exp)
(tagged-list? exp 'let))
(define (let-bindings exp)
(cadr exp))
(define (let-variables exp)
(map car (let-bindings exp)))
(define (let-values exp)
(map cadr (let-bindings exp)))
(define (let-body exp)
(cddr exp))
(define (let->combination exp)
((make-lambda (let-variables exp)
(let-body exp))
(let-values exp)))
(define (make-let bindings body)
(list 'let bindings body))
; 将 let? 放在 (application? exp) 之前即可。
(define (eval exp env)
(cond ((self-evaluating? exp) exp)
((variable? exp) (lookup-variable-value exp env))
((quoted? exp) (text-of-quotation exp))
((assignment? exp) (eval-assignment exp env))
((definition? exp) (eval-definition exp env))
((if? exp) (eval-if exp env))
((lambda? exp)
(make-procedure (lambda-parameters exp)
(lambda-body exp)
env))
((begin? exp)
(eval-sequence (begin-actions exp) env))
((cond? exp)
(eval (cond->if exp) env))
((let? exp)
(eval (let->combination exp) env))
((application? exp)
(apply (eval (operator exp) env)
(list-of-values (operands exp) env)))
(else
(error "Unknown expression type -- EVAL " env))))