SICP 全笔记

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.

Ben 的观点是将 unless 设计得与 if,define 等等关键字一样,成为一个 special form。即在 eval 去主动识别 unless 语句,与 ifcond 一样。这实际不算是 lazy evaluation,只是一种语法上的替换。

Alyssa 的反对在于 unless 如果变成了 special form 之后,我们就不能把 unless 当做参数传递到过程中了。因为 special form 是不存在于 environment 里面的。这与我们不能把 ifdefinelambdalet 等关键字当做过程参数的原因一样:applicative order 将会对每一个参数进行求值,如果传递了 unless,那么作为 special formunless 将无法在 environment 中找到相应的值,于是出现错误。(我们自己写的 eval 将会报告 unlessunbound variable,现代解释器将会报告 unless 是 syntactic keyword)