<< Previous exercise (4.5) | Index | Next exercise (4.7) >>


 ;; in eval, add this: 
  ((let? expr) (evaln (let->combination expr) env)) 
 ;; let expression 
 (define (let? expr) (tagged-list? expr 'let)) 
 (define (let-vars expr) (map car (cadr expr))) 
 (define (let-inits expr) (map cadr (cadr expr))) 
 (define (let-body expr) (cddr expr)) 
 (define (let->combination expr) 
   (list (make-lambda (let-vars expr) (let-body expr)) 
         (let-inits expr))) 

Because the initial values for the vars serve as the remainder of the list (cdr) instead of a separate list, the let->combination should be defined using 'cons' instead of 'list'.

 (define (let->combination expr) 
   (cons (make-lambda (let-vars expr) (let-body expr)) 
         (let-inits expr))) 

I think let-body above seems to have a bug.

 (define (let-body expr) (caddr expr)) 

because body part is one of three parts of let expression list.

Body part may contain several expressions, so 'cddr' is used to point all the rest parts.