sicp-ex-5.43



<< Previous exercise (5.42) | Index | Next exercise (5.44) >>


meteorgan

  
  
 ;; we just need use scan-out-defines here change lambda-body to 
 ;; equivalent expression. 
 (define (compile-lambda-body exp proc-entry ct-env) 
   (let ((formals (lambda-parameters exp))) 
     (append-instruction-sequences 
       (make-instruction-sequence '(env proc argl) '(env) 
         `(,proc-entry 
           (assign env (op compiled-procedure-env) (reg proc)) 
           (assign env 
                   (op extend-environment) 
                   (const ,formals) 
                   (reg argl) 
                   (reg env)))) 
       (compile-sequence 
         (scan-out-defines (lambda-body exp)) 
         'val 'return 
         (extend-ct-env ct-env formals))))) 

codybartfast




I needed to make two changes to the original scan-out-defines:

  1. Instead of transforming to a let expression (as implied by 4.1.6), I
     transformed directly to a lambda expression. Alternatively, I could
     have added let support to the compiler.

  2. *unassigned* needed to be double quoted, i.e.:

       ''*unassigned*

     otherwise, when the compiler analyzed the lambda expression it would
     interpret *unassigned* as a variable name.