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

Exercise 4.78 · 习题

Exercise 4.78: Redesign the query language as a

nondeterministic program to be implemented using the evaluator of

4.3, rather than as a stream process. In this approach, each query will

produce a single answer (rather than the stream of all answers) and the user

can type try-again to see more answers. You should find that much of

the mechanism we built in this section is subsumed by nondeterministic search

and backtracking. You will probably also find, however, that your new query

language has subtle differences in behavior from the one implemented here. Can

you find examples that illustrate this difference?

练习 4.78:将查询语言重新设计为一个非确定性程序 (nondeterministic program),以 4.3 节的求值器来实现,而不是以流计算过程来实现。在这种方法中,每次查询只产生一个答案(而非所有答案构成的流),用户可以键入 try-again 来查看更多答案。你会发现,本节所构建的大量机制可被非确定性搜索与回溯所涵盖。然而,你可能也会发现,新的查询语言在行为上与此处实现的版本存在微妙差异。你能找到说明这种差异的例子吗?