On Jul 17, 2010, at 9:46 PM, Isaac Hodes wrote: > I did check out your response: it's rather fast on my machine. it's > not really functional, though, as you use the `let` macro as a way of > procedurally executing a lot of functions. This isn't bad at all, but > you're not composing functions.
'Functional' means simply avoiding mutation and side-effects. How the code is organized is a separate issue. In case you're interested, I made a small change to the code I posted before that makes it significantly faster. I don't know what you consider 'slow', but it takes 2-3x as long as your imperative Python version on my hardware (less if I replace the outermost map with pmap, depending on the input sizes). I think that's quite acceptable, especially given Clojure's relative youth as a language. (defn convolve-indices [i max-m max-n] "Lists all index pairs adding up to i, where the first index is less than max-m and the second is less than max-n." (map #(vector % (- i %)) (range (max 0 (inc (- i max-n))) (min (inc i) max-m)))) (defn convolve-1 [i ms ns] "Returns the ith value of the convolution of ms with ns." (reduce + (map (fn [[m n]] (* (ms m) (ns n))) (convolve-indices i (count ms) (count ns))))) (defn convolve [ms ns] "Convolves ms with ns." (map #(convolve-1 % ms ns) (range (dec (+ (count ms) (count ns)))))) -- 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 Note that posts from new members are moderated - please be patient with your first post. 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