On Sunday, August 19, 2012, Ian Tegebo wrote:

> I want to,
>
> (take k (in-generator (infinite-generator (yield (random n)))))
>
> where k and n are positive integers, k<n.
>
> Unfortunately, 'in-generator' returns a sequence while 'take' needs a
> list and calling 'sequence->list' results in an error.  So, I thought
> maybe I needed 'take' from 'lazy'.  But it also complains about the
> index being too large.
>


The take function works on lists, and although what you have in hand is a
sequence, not all sequences are lists.

You should be able to take the first k elements of that sequence like this:

;;;;;;
(for/list ([elt (in-generator (infinite-generator (yield (random n))))]
         [i k])
   elt)
;;;;;;

There may be an easier way to to do this, but using the for/list loop
should do the trick.  Good luck!
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to