[racket] Making a Racket function "recallable"

From: Joe Gilray (jgilray at gmail.com)
Date: Tue Feb 14 03:27:05 EST 2012

Thanks Danny,

Now I can use the original recursive formulation:

; function to use the fib-stream to generate a list of all fibs < n
(define (fib-stream-less-than-n n)
  (let ([fib-val (stream-first fib-stream)])
    (if (>= fib-val n) '() (cons fib-val (fib-less-than-n n)))))

I've learned a lot tonight.  I have been reading the manuals, but they are
hard to get your arms around when you are just starting out. Also it would
be great if the manuals had more and longer examples.  Have anyone looked
into doing a Racket "cookbook"?

Thanks again,
-Joe

On Mon, Feb 13, 2012 at 9:55 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:

> On Tue, Feb 14, 2012 at 12:32 AM, Joe Gilray <jgilray at gmail.com> wrote:
> > 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?
>
>
> A stream is a sequence, and also has a few more functions that act
> very much like the familiar list-oriented functions.
>
>    http://docs.racket-lang.org/reference/streams.html#(tech._stream)
>
> So you could use stream-first and stream-rest on the fib-stream, as if
> you had entire fibonacci sequence in front of you as an infinite list.
>  Just don't try to stream->list it.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120214/c2aa499f/attachment.html>

Posted on the users mailing list.