I wrote what I think is the idiomatic version. Idiomatically, you delay execution of functions over lazy sequences, so if you get a sequence of a million words and you only take the first 100, you don't lowercase (or whatever else) the entire sequence. Also a smart compiler on a multi-core machine could do a much better job dispensing the computation with a program written this way. I doubt today's JITs are this smart, but I'm sure someday soon they will be. Of course, this doesn't apply to this specific example with slurp, because how it works as the inner most function. But again, I was being idiomatic. If you need a blazing fast implementation for this specific task, I suspect perl would be a better choice.
Mibu On Dec 26, 7:11 pm, Piotr 'Qertoip' Włodarek <qert...@gmail.com> wrote: > On Dec 25, 4:58 pm, Mibu <mibu.cloj...@gmail.com> wrote: > > > My version: > > > (defn top-words [input-filename result-filename] > > (spit result-filename > > (apply str > > (map #(format "%s : %d\n" (first %) (second %)) > > (sort-by #(-(val %)) > > (reduce #(conj %1 { %2 (inc (%1 %2 0)) }) {} > > (map #(.toLowerCase %) > > (re-seq #"\w+" > > (slurp > > input-filename))))))))) > > > Mibu > > Once you move .toLowerCase right after slurp, it gets 3 times faster. > > regards, > Piotrek --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---