I've been struggling with streams recently too. in-producer
<http://docs.racket-lang.org/reference/sequences.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._in-producer%29%29>
solved
my problems.

(define name-gen
  (in-producer (lambda () (new-name ethnicity sex))))

(define some-names
  (for/list ([name name-gen] [i (in-range 10)]) name))

On Sun, Dec 20, 2015 at 9:48 PM, mark <[email protected]> wrote:

>
> Hi, there.  I have just started playing with Racket and would like some
> help with using streams/generators (I am not particularly versed in
> programming in a functional style and am attempting to learn :-))
>
> So I have a function called (new-name) that creates a random name, like
> "Bob Brown" or "Jill Xi".  It looks something like
>
>  (define (new-name ethnicity sex)
>   ; return a string like "First LAST" based on ethnicity and sex)
>
> This is all good and dandy and works well.  What I would like to do now is
> something like
>
>   (define name-gen
>     (infinite-generator
>        (yield (new-name ethnicity sex))))  ; won't work...
>
>   (get-some-names (name-gen "anglo" "male") 10) ; not sure about this...
>
> Which would, from a generated list or stream, return ten names.  I can do
> this using something like
>
>  (for/list ([i 10])
>    (new-name "anglo" "male"))
>
> but that seems to miss out on the goodness of streams/generators.
>
> Any help/tips appreciated.
>
> TIA, .. mark.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to