> The obvious way is like the following, which traverse the sequence 2 times. > Wondering what will be the efficient way...
(defn avg [coll] (loop [c coll tot 0 cnt 0] (if (empty? c) (/ tot cnt) (recur (rest c) (+ tot (first c)) (inc cnt))))) This will loop only once. It happens to be faster, but the difference is not explained by (count coll) elimination only. Maybe reduce is a factor as well. -- 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