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
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]
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
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
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.