灯下 登录
计算机科学 / SICP / 4.4.4 Implementing the Query System

Exercise 4.77 · 习题

Exercise 4.77: In 4.4.3 we saw

that not and lisp-value can cause the query language to give

“wrong” answers if these filtering operations are applied to frames in which

variables are unbound. Devise a way to fix this shortcoming. One idea is to

perform the filtering in a “delayed” manner by appending to the frame a

“promise” to filter that is fulfilled only when enough variables have been

bound to make the operation possible. We could wait to perform filtering until

all other operations have been performed. However, for efficiency’s sake, we

would like to perform filtering as soon as possible so as to cut down on the

number of intermediate frames generated.

练习 4.77:在 4.4.3 中我们看到,当 not 和 lisp-value 这些过滤操作应用于含有未绑定变量的框架时,查询语言可能给出"错误的"答案。请设计一种修正这一缺陷的方法。一种思路是以"延迟"方式执行过滤:向框架追加一个"过滤承诺",只有当足够多的变量已完成绑定、使得操作可以执行时,才兑现这个承诺。我们可以等到所有其他操作都完成后再执行过滤。但出于效率考虑,我们希望尽早执行过滤,以减少产生的中间框架数量。