Re: Default random in Clojure doesn't seem to fit fp paradigm

2012-12-06 Thread Stuart Halloway
Yes, that fix needs to be made, patch welcome. I also have considered making a protocol for random so that (1) other impls can be used and (2) easier to port to ClojureScript. Stu On Thu, Dec 6, 2012 at 9:15 AM, Asim Jalis wrote: > On Thu, Dec 6, 2012 at 5:40 AM, Stuart Sierra > wrote: > >> T

Re: Default random in Clojure doesn't seem to fit fp paradigm

2012-12-06 Thread Asim Jalis
On Thu, Dec 6, 2012 at 5:40 AM, Stuart Sierra wrote: > The data.generators library has versions of these functions that use a > fixed seed and a rebindable Random instance. > > https://github.com/clojure/data.generators Looking at https://github.com/clojure/data.generators/blob/master/src/main/c

Re: Default random in Clojure doesn't seem to fit fp paradigm

2012-12-06 Thread Stuart Sierra
The data.generators library has versions of these functions that use a fixed seed and a rebindable Random instance. https://github.com/clojure/data.generators -S -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to cl

Re: Default random in Clojure doesn't seem to fit fp paradigm

2012-12-05 Thread JonC
On Wednesday, December 5, 2012 10:30:26 PM UTC, Karsten Schmidt wrote: > > FWIW dynvars are quite a common solution to these kind of scenarios: > And that's an excellent solution. However, I still think that it's a problem that shouldn't need solving in the first place - the basic library sho

Re: Default random in Clojure doesn't seem to fit fp paradigm

2012-12-05 Thread Karsten Schmidt
FWIW dynvars are quite a common solution to these kind of scenarios: e.g. In my own library I've defined a default Random instance which is used by all related library fns, e.g.: (def ^:dynamic ^java.util.Random *rnd* (java.util.Random. 23)) (defn random ([x] (* x (.nextDouble *rnd*))) ([x y]

Re: Default random in Clojure doesn't seem to fit fp paradigm

2012-12-05 Thread JonC
On Wednesday, December 5, 2012 8:45:00 PM UTC, miner wrote: > > You should treat rand and friends like i/o. Don't bury them deep in your > code. Write your pure functions so that they take a seed value (or > sequence). This is one approach to by-passing clojure's randoms, yes. (To be hone

Re: Default random in Clojure doesn't seem to fit fp paradigm

2012-12-05 Thread Steve Miner
You should treat rand and friends like i/o. Don't bury them deep in your code. Write your pure functions so that they take a seed value (or sequence). Generate the random values from outside of the important functions, maybe providing a convenience wrapper function around your main logic. (

Default random in Clojure doesn't seem to fit fp paradigm

2012-12-05 Thread JonC
Ok: first of all, Clojure has outstandingly the best core library I've seen. I am awed by how wonderfully the protocol approach makes data structures, and the good taste applied to getting an API that's reasonably minimal and wonderfully complete. I've not posted before because I've had nothing