SICP Exercise 4.16 interpreting internal definitions

Exercise 4.16.  In this exercise we implement the method just described for interpreting internal definitions. We assume that the evaluator supports let (see exercise 4.6).

a.  Change lookup-variable-value (section 4.1.3) to signal an error if the value it finds is the symbol *unassigned*.

b.  Write a procedure scan-out-defines that takes a procedure body and returns an equivalent one that has no internal definitions, by making the transformation described above.

c.  Install scan-out-defines in the interpreter, either in make-procedure or in procedure-body (see section 4.1.3). Which place is better? Why?

SOLUTION

The code and tests are here.

It is better to install 'scan-out-defines' in 'make-procedure' because by doing this the transformation of the procedure body happens only once for a given procedure during definition time. If we install it in 'procedure-body' the transformation will happen every time the procedure is executed. This would be wasteful.

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