adrianwong programmer · retired coal miner

SICP section 3.2 - the environment model of evaluation

All diagrams in this post were created with draw.io.

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 draw.io diagram

Environments created by the iterative version:

SICP 3.09b draw.io 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 draw.io diagram

Environments after the call to W1:

SICP 3.10b draw.io 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 draw.io diagram

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

SICP 3.11b draw.io 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.