4.22 Exercise 4.22

Adding support for let expressions in this new analyzing interpreter is nearly trivial, because previously we supported them by transforming them into a form we already supported – namely, that of an immediately invoked anonymous function.

(define (analyze exp)
  (cond ((self-evaluating? exp)
         (analyze-self-evaluating exp))
        ((quoted? exp) (analyze-quoted exp))
        ((variable? exp) (analyze-variable exp))
        ((assignment? exp) (analyze-assignment exp))
        ((definition? exp) (analyze-definition exp))
        ((if? exp) (analyze-if exp))
        ((lambda? exp) (analyze-lambda exp))
        ((begin? exp) (analyze-sequence (begin-actions exp)))
        ((cond? exp) (analyze (cond->if exp)))
        ((let? exp) (analyze (let->combination exp)))
        ((application? exp) (analyze-application exp))
        (else
         (error "Unknown expression type -- ANALYZE" exp))))

I say almost trivial because scan-out-defines does not work immediately like this, since the procedure has already been analyzed at the time when it is called. TODO: Remove this limitation...