[racket] taking from a generator, and a possible bug
On Sat, Aug 18, 2012 at 10:39 PM, Richard Cleis <rcleis at me.com> wrote:
> Are you looking for something like this?
>
> (define (tr2 k n) (build-list k (lambda (x) (random n))))
Nice, I hadn't paid enough attention to `build-list` - I'll use it in
place of my `call-n-times`. While I don't think this addresses the
larger issue with large/infinite streams/generators, I'll certainly
use this trick for small lists.
> On Aug 18, 2012, at 10:59 PM, Ian Tegebo wrote:
>
>> (define (call-n-times f n)
>> (define (helper f n lst)
>> (if (< n 1)
>> lst
>> (helper f (- n 1) (cons (f) lst))))
>> (helper f n '()))
>>
>> (define (take-randoms k n)
>> (call-n-times (curry random n) k))
>
Thanks,
--
Ian Tegebo