A couple more updates to these: > (defn random-permutation [s] > "Return a random permutation of this seq." > (let [arr (to-array s) len (alength arr)] > (dotimes [i (dec len)] > (let [r (+ i (rand-int (- len i))), > prev (aget arr i)] > (aset arr i (aget arr r)) > (aset arr r prev))) > (seq arr)))
Per [1] this thread, (defn shuffle-java "Shuffles coll using a Java ArrayList. Blows shuffle out of the water on speed and space." [coll] (let [l (ArrayList. coll)] (Collections/shuffle l) (seq l))) is both much simpler and much much much faster than my implementation. [1] http://groups.google.com/group/clojure/browse_thread/thread/180842eb58c58370 > (defmacro lazy-get "Like get but lazy about evaluating the default > value" > [m k d] > `(if-let [pair# (find ~m ~k)] > (second pair#) > ~d)) This should be (defmacro lazy-get "Like get but lazy about evaluating the default value" [m k d] `(if-let [pair# (find ~m ~k)] (val pair#) ~d)) Changing the "second" to a "val" speeds both this and safe-get up by more than a factor of 4! [2] [2] http://w01fe.com/blog/2009/01/more-on-clojure-map-accessor-speeds/ Also, once again (Chouser?), is there anything I can do to help implement the changes we've talked about? I can try to make patches for the changes in core, and/or improve and document other utilities for clojure.contrib, if that would be helpful. Cheers, Jason --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---