灯下 登录
计算机科学 / SICP / 4.2.1 Normal Order and Applicative Order

Exercise 4.26 · 习题

Exercise 4.26: Ben Bitdiddle and Alyssa

P. Hacker disagree over the importance of lazy evaluation for implementing

things such as unless. Ben points out that it’s possible to implement

unless in applicative order as a special form. Alyssa counters that, if

one did that, unless would be merely syntax, not a procedure that could

be used in conjunction with higher-order procedures. Fill in the details on

both sides of the argument. Show how to implement unless as a derived

expression (like cond or let), and give an example of a situation

where it might be useful to have unless available as a procedure, rather

than as a special form.

练习 4.26:Ben Bitdiddle 和 Alyssa P. Hacker 就惰性求值对于实现 unless 之类结构的重要性意见不一。Ben 指出,完全可以在应用序中将 unless 实现为一种特殊形式。Alyssa 反驳说,如果那样做,unless 就只是一种语法,而不再是一个能与高阶过程配合使用的过程了。请分别为双方的论点补充论据。说明如何将 unless 作为派生表达式来实现(类似 cond 或 let),并给出一个具体例子,说明在某些情况下将 unless 作为过程而非特殊形式会更有用。