Danny is correct... ouch (/.\ <- covering my head in shame).<div><br></div><div>Anyway to close the chapter on this, below is the final result using Danny's stream suggestions/code. I also have a non-streams version thanks to Erik (and Stephen and Joshua).</div>
<div><br></div><div>-Joe</div><div><br></div><div><div>#lang racket</div><div>(require racket/sequence)</div><div><br></div><div><div>; a sequence function that creates an "infinite" sequence then turns that into a stream that remembers its previous values as we walk across it.</div>
<div>; invoke in a loop-expr (see below)</div><div>(define fib-stream</div><div> (let ([fib-sequence (in-producer (fib) 'donttellmecauseithurts)])</div><div> (sequence->stream fib-sequence)))</div><div><br></div>
<div>; function to generate a list of all values in a stream < n</div><div>(define (stream-less-than-n n strm)</div><div> (let ([fib-val (stream-first strm)])</div><div> (if (>= fib-val n) '() (cons fib-val (stream-less-than-n n (stream-rest strm))))))</div>
</div><div><br></div><br><div class="gmail_quote">On Wed, Feb 15, 2012 at 9:19 AM, Danny Yoo <span dir="ltr"><<a href="mailto:dyoo@cs.wpi.edu">dyoo@cs.wpi.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wed, Feb 15, 2012 at 3:10 AM, Joe Gilray <<a href="mailto:jgilray@gmail.com">jgilray@gmail.com</a>> wrote:<br>
> The code that Danny wrote to create fib-stream works great with his<br>
> peek-fibs function, but I really don't understand stream-first.<br>
><br>
> I wrote:<br>
><br>
> ; function to use the fib-stream to generate a list of all fibs < n<br>
> (define (fib-stream-less-than-n n)<br>
> (let ([fib-val (stream-first fib-stream)])<br>
> (if (>= fib-val n) '() (cons fib-val (fib-less-than-n n)))))<br>
</div> ^^^^^^^^^^^^^^^^<br>
<br>
Are you sure you mean to use fib-less-than-n here?<br>
</blockquote></div><br></div>