Danny,<div><br></div><div>Thanks for the explanations. These are powerful ideas. It appears not to generate the sequence until needed, very nice.</div><div><br></div><div>How could I modify this to do the "less than n" idea?</div>
<div><br></div><div>-joe<br><br><div class="gmail_quote">On Mon, Feb 13, 2012 at 9:20 PM, 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">> (let ([fib-sequence (in-producer fib 'donttellmecauseithurts)])<br>
<br>
</div>I realize that I forgot to add explanation.<br>
<br>
This line creates a "sequence" by repeatedly calling your fib<br>
function. in-producer will continue to call fib until it sees the<br>
second argument. But since the fibonacci numbers don't end, I want to<br>
tell in-producer to go on forever, so I passed it something that fib<br>
won't ever produce.<br>
<br>
... and It's from a song by the music group No Doubt. Why? Dunno.<br>
Valentine's Day brought it to mind for some reason. :)<br>
<br>
<br>
The second part:<br>
<div class="im"><br>
;; Let's wrap it and turn it into a stream that remembers...<br>
(sequence->stream fib-sequence)<br>
<br>
</div>turns the sequence into another sequence. But this one will remember<br>
its previous values as we walk across it.<br>
<br>
<br>
So when we do start walking the streamified sequence, we can do that<br>
repeatedly without losing the old values.<br>
</blockquote></div><br></div>