adrianwong ((◕ᴥ◕) ((◕ᴥ◕) ())))

SICP section 3.2 - the environment model of evaluation

All diagrams in this post were created with

Selected exercises

Exercise 3.09

For ease of diagramming, I’m evaluating (factorial 3) instead of (factorial 6).

Environments created by the recursive version:

SICP 3.09a diagram

Environments created by the iterative version:

SICP 3.09b diagram

Exercise 3.10

Again, for ease of diagramming, I’m omitting the environments created as a result of evaluating (define W2 (make-withdraw 100)).

Environments created by applying the procedure object W1:

SICP 3.10a diagram

Environments after the call to W1:

SICP 3.10b diagram

With this version of make-withdraw, an additional environment E2 is created, in which balance is bound to the value of the initial-amount parameter.

Exercise 3.11

Environments created by the first application of the procedure object acc (deposit):

SICP 3.11a diagram

Environments after the first call to acc, plus the ones created by the second application of acc (withdraw):

SICP 3.11b diagram

If another account acc2 is defined, its local state will be kept in its own environment, separate from the environment which keeps the local state for acc.