Exercise 3.11.  In section 3.2.3 we saw how the environment model 
described the behavior of procedures with local state. Now we have seen 
how internal definitions work. A typical message-passing procedure 
contains both of these aspects. Consider the bank account procedure of 
section 3.1.1:

(define (make-account balance)
  (define (withdraw amount)
    (if (>= balance amount)
        (begin (set! balance (- balance amount))
               balance)
        "Insufficient funds"))
  (define (deposit amount)
    (set! balance (+ balance amount))
    balance)
  (define (dispatch m)
    (cond ((eq? m 'withdraw) withdraw)
          ((eq? m 'deposit) deposit)
          (else (error "Unknown request -- MAKE-ACCOUNT"
                       m))))
  dispatch)

Show the environment structure generated by the sequence of interactions

(define acc (make-account 50))

((acc 'deposit) 40)
90

((acc 'withdraw) 60)
30

Where is the local state for acc kept? Suppose we define another account

(define acc2 (make-account 100))

How are the local states for the two accounts kept distinct? Which parts 
of the environment structure are shared between acc and acc2?

————————————————————————————————————————————————————————————————————————

After

(define acc (make-account 50))

((acc 'deposit) 40)
90

((acc 'withdraw) 60)
30

the global environment contains a binding of acc to the dispatch 
procedure returned from the make-account call.

The environment of the acc procedure is the environment created by the 
evaluation of make-account.  This environment binds values to balance, 
withdraw, deposit, and dispatch.

If another account acc2 is defined by evaluating (make-account 100), a 
new frame will be created with new bindings for balance, withdraw, 
deposit, and dispatch.  Since these procedures all point to the 
environment in which they were created, each call to make-account 
creates procedures which will modify the correct balance.
