<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi. <div><br></div><div>Was going over <a href="http://jeapostrophe.github.io/2013-06-03-hanoi-post.html">Jay's Towers of Hanoi</a> implementation that makes use of Racket streams. I find this comment confusing and would appreciate a more elaborate explanation:</div><div><br></div><div><blockquote type="cite"><!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

<span class="Apple-style-span" style="font-family: Menlo; ">It’s important, using racket/stream, to use the stream-cons because if you wrote a stream-append with three arguments, then the second recursive call wouldn’t be lazily evaluated and you’d save nothing by using streams over lists. That’s because stream-append is a function, while stream-cons is a macro that thunks its arguments. </span></blockquote></div><div><br></div><div>Ok, so I assume what he means is that procedure arguments get evaled during application. Since (stream-append ..) is a procedure, the result of the second recursive call (last arg) would be forced. Docs for (stream-append ..) however say <a href="http://docs.racket-lang.org/reference/streams.html#(def._((lib._racket/stream..rkt)._stream-append))">this</a>:</div><div><br><blockquote type="cite"><!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

<span class="Apple-style-span" style="font-family: Menlo; ">new stream is constructed lazily, while the last given stream is used in the tail of the result. </span></blockquote></div><div><br></div><div>I find this confusing. What does "costruct lazily" mean then? Does this phrase say that (n-1) args to it aren't forced, but the last one is? But append is a procedure, so all args should be evaled.</div><div><br></div><div>As a side thought, I think I could cheat (like stream-cons) by thunking stuff I pass to append, thunk is a wrapping macro, right?</div><div><br></div><div><blockquote type="cite"><!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

<span class="Apple-style-span" style="font-family: Menlo; ">(stream-append (thunk (towers (sub1 n) from extra to))</span><div style="font-family: Menlo; "><div>               (thunk (move from to))</div><div>               (thunk (towers (sub1 n) extra to from)))<br></div></div></blockquote></div><div><div style="font-family: Menlo; "><div><br></div><div>thx!</div></div></div><div><div apple-content-edited="true">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">---</div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Vlad Kozin <<a href="mailto:vladilen.kozin@gmail.com">vladilen.kozin@gmail.com</a>><br><br><br></div></div>
</div>
<br></div></body></html>