so ... the H1 recursion is evaluating it's arguments, producing a list
instead of a stream?

I based this on the ones function with the H1 helper function to act as
a toggle.

However, closer adherence to the 'ones' example and consing both values
at the same time works just fine, and is much more concise:-

(define (dan-then-dog)
  (stream-cons dan
               (stream-cons dog (dan-then-dog))
  ))


Thanks,
Patrick Sweetman

On 19/05/2013 14:06, Robby Findler wrote:
> If you were to replace stream-cons with this function:
> 
> (define (not-stream-cons x y) (printf "x ~s y ~s\n" x y) 'something-random)
> 
> would it make sense to you what happens?
> 
> Robby
> 
> 
> On Thu, May 16, 2013 at 7:30 AM, Patrick Sweetman
> <sweetma...@woosh.co.nz <mailto:sweetma...@woosh.co.nz>> wrote:
> 
>     I'm doing this problem:
> 
>     6. Write a stream dan-then-dog, where the elements of the stream
>     alternate between the strings "dan.jpg" and "dog.jpg" (starting with
>     "dan.jpg"). More specically, dan-then-dog should be a thunk that when
>     called produces a pair of "dan.jpg" and a thunk that when called
>     produces a pair of "dog.jpg" and a thunk that when called... etc. Sample
>     solution: 4 lines.
> 
>     and I cannot for the life of me understand why the following code does
>     not produce a properly thunked stream. It evaluates the entries until it
>     runs out of memory
> 
>     (define dan "dan.jpg")
>     (define dog "dog.jpg")
> 
>     (define (dan-then-dog)
>       (define (H1 st0 b0)
>         (cond
>           [(= b0 1) (H1 (stream-cons dan st0) 0)]
>           [else     (H1 (stream-cons dog st0) 1)]
>           )
>         )
>       (H1 empty-stream 1))
> 
>     Can somebody please explain why my understanding of Racket streams is
>     faulty?
> 
>     Thanks,
>     Patrick Sweetman
>     ____________________
>       Racket Users list:
>       http://lists.racket-lang.org/users
> 
> 

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to