<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><br><div><div>On May 19, 2012, at 2:45 PM, Michael Rice wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>From pg. 399 in SICP:</div><div><br></div><div>An example that exploits lazy evaluation is the definition of a procedure unless</div><div><br></div><div>(define (unless condition usual-value exceptional-value)</div><div>
(if condition exceptional-value usual-value))</div><div><br></div><div>===</div><div><br></div><div>Huh? For both applicative and normal order, wouldn't both exceptional-value AND usual-value be evaluated, or not, depending on condition?</div></blockquote></div><br><div>SHORT: If 'unless' were defined as a CALL-BY-NAME [*] function or as a in a LAZY dialect of Racket, you would get away with this strategy.</div><div><br></div><div>LONG: To try it out, use the lazy language, define it like this, and run: </div><div><br></div><div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000">Welcome to DrRacket, version 5.3.0.8--2012-05-16(3fceae27/d) [3m].</font></div><div><font class="Apple-style-span" color="#000000">Language: lazy.</font></div><div><font class="Apple-style-span" color="#000000">> (define (unlss condition then-branch else-branch)</font></div><div><font class="Apple-style-span" color="#000000"> (if condition then-branch else-branch))</font></div><div><font class="Apple-style-span" color="#000000">> (unlss #t (+ 1 1) (/ 1 0))</font></div><div><font class="Apple-style-span" color="#000000">2</font></div></blockquote><div><br></div>See the division by 0 does not raise an error, it is never evaluated. The prompt forces the evaluation of (+ 1 1). (In a truly lazy language, it shouldn't even do that, but never mind this small quibble.) <br><br></div><div>;; ---</div><div><br></div><div>If you'd like to understand how this works in the world of Racket, take a look at this section on creating languages in Racket. It is a part of a short essay I wrote a year ago or so: </div><div><br></div><div> <a href="http://www.ccs.neu.edu/home/matthias/Thoughts/Racket_is____.html#(part._.Creating_a_.Language)">http://www.ccs.neu.edu/home/matthias/Thoughts/Racket_is____.html#(part._.Creating_a_.Language)</a></div><div><br></div><div>;; --- </div><div><br></div><div>FOOTNOTE: SICP gets it wrong when it refers to APPLICATIVE and NORMAL ORDER evaluation. Both are terms that may have been useful in the world of Lambda Calculus mathematics in the 1930s and 1940s. This whole view that the EVALUATION STRATEGY is related to Programming Language parameter passing mechanism was debunked in the 1970s by Plotkin's seminal paper on Call-by-name, call-by-value, and the Lambda Calculus [TCS 1974]. We can forgive SICP 1e for making this mistake, SICP 2e shouldn't propagate it. </div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></body></html>