[racket] Towers of Hanoi with Racket streams

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Wed Oct 9 14:05:47 EDT 2013

> 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 this:
>
> new stream is constructed lazily, while the last given stream is used in the
> tail of the result.
>
> 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.

It means the resulting composite list is constructed lazily. Something
like this:

(define (append lst1 lst2)
  (if (null? lst1)
      lst2
      (cons (car lst1) (delay (append (cdr lst1) lst2)))))

It says nothing about evaluation of arguments to append, which is
determined by the language.





>
> 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?
>
> (stream-append (thunk (towers (sub1 n) from extra to))
>                (thunk (move from to))
>                (thunk (towers (sub1 n) extra to from)))
>
>
> thx!
> ---
> Vlad Kozin <vladilen.kozin at gmail.com>
>
>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>

Posted on the users mailing list.