[racket] Making a Racket function "recallable"
Danny,
Thanks for the explanations. These are powerful ideas. It appears not to
generate the sequence until needed, very nice.
How could I modify this to do the "less than n" idea?
-joe
On Mon, Feb 13, 2012 at 9:20 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> > (let ([fib-sequence (in-producer fib 'donttellmecauseithurts)])
>
> I realize that I forgot to add explanation.
>
> This line creates a "sequence" by repeatedly calling your fib
> function. in-producer will continue to call fib until it sees the
> second argument. But since the fibonacci numbers don't end, I want to
> tell in-producer to go on forever, so I passed it something that fib
> won't ever produce.
>
> ... and It's from a song by the music group No Doubt. Why? Dunno.
> Valentine's Day brought it to mind for some reason. :)
>
>
> The second part:
>
> ;; Let's wrap it and turn it into a stream that remembers...
> (sequence->stream fib-sequence)
>
> turns the sequence into another sequence. But this one will remember
> its previous values as we walk across it.
>
>
> So when we do start walking the streamified sequence, we can do that
> repeatedly without losing the old values.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120213/e5814b76/attachment-0001.html>