灯下 登录
计算机科学 / SICP / 4.1.6 Internal Definitions

Exercise 4.16 · 习题

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).

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

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.

Install scan-out-defines in the interpreter, either in

make-procedure or in procedure-body (see 4.1.3).

Which place is better? Why?

练习 4.16:在本练习中,我们实现刚才描述的解释内部定义的方法。我们假设求值器支持 let(参见练习 4.6)。

修改 lookup-variable-value(4.1.3),使其在找到的值是符号 *unassigned* 时发出错误信号。

写一个过程 scan-out-defines,它接受一个过程体并返回等价的过程体,其中不含内部定义,方法是进行上述变换。

将 scan-out-defines 安装到解释器中,安装在 make-procedure 或 procedure-body 中均可(参见 4.1.3)。哪个位置更好?为什么?