SICP Exercise 4.17 scan-out-defines

Exercise 4.17.  Draw diagrams of the environment in effect when evaluating the expression <e3> in the procedure in the text, comparing how this will be structured when definitions are interpreted sequentially with how it will be structured if definitions are scanned out as described. Why is there an extra frame in the transformed program? Explain why this difference in environment structure can never make a difference in the behavior of a correct program. Design a way to make the interpreter implement the "simultaneous'' scope rule for internal definitions without constructing the extra frame.

SOLUTION

The progressive environment diagrams are here. There is an extra frame in the transformed program because the evaluator transforms the 'let' expression into a lambda expression which becomes another procedure object which executes in a new frame.

One of the purposes of the environment structure is to ensure that each procedure execution gets a separate space for its name-value bindings (be they bindings for data or procedures/code). The environment management procedures and the linked frame structure ensure that the correct behaviour of any program is enforced. That is why the difference in environment structure (in the transformed program) does not make a difference in the behaviour.










Comments

Popular posts from this blog

SICP Exercise 2.56 differentiation rule

SICP Exercise 1.28 (Miller-Rabin Test)

SICP Exercise 4.18 a alternative strategy for interpreting internal definitions