Re: take repeatedly alternative?

2009-11-20 Thread Raoul Duke
as an aside, sometimes you want the rng to be truly pure so you can easily recreate situations. take a look at randomness in haskell for fun. :-) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups

Re: take repeatedly alternative?

2009-11-19 Thread John Harrop
On Thu, Nov 19, 2009 at 9:17 PM, Mark Triggs wrote: > A good example is: > > (take 10 (repeatedly #(rand-int 100))) > > to get a bunch of random integers. I actually quite like this idiom, > even if there's a bit of ascii involved :) > Why not abstract it some, though? (defn rand-seq [range]

Re: take repeatedly alternative?

2009-11-19 Thread Mark Triggs
A good example is: (take 10 (repeatedly #(rand-int 100))) to get a bunch of random integers. I actually quite like this idiom, even if there's a bit of ascii involved :) Mark Tom Hicks writes: > I'm not quite sure why you would want to say > > (take n (repeatedly fn)) > > It appears to

Re: take repeatedly alternative?

2009-11-19 Thread Tom Hicks
I'm not quite sure why you would want to say (take n (repeatedly fn)) It appears to me that a fn called 'repeatedly' is really being executed for its side-effects. If you are interested in a sequence of values being returned from fn, then make fn return a lazy sequence and 'take' will work on t

take repeatedly alternative?

2009-11-18 Thread Raoul Duke
when people use (take n (repeatedly fn)) are there other ways they might have written that in clojure? it just seems like more ascii than should be required :-) e.g. not exactly the same but bigloo has list-tabulate http://www-sop.inria.fr/mimosa/fp/Bigloo/doc/bigloo-7.html#list-tabulate gracias.