On Mon, Dec 28, 2009 at 9:39 PM, Timothy Pratley
<timothyprat...@gmail.com> wrote:
> I find this quite interesting because Meikel has effectively created a
> faster version of reductions:
>
> (defn cumulative
>  ([accum-fn s]
>   (rest (cumulative accum-fn 0 s)))
>  ([accum-fn accum s]
>   (lazy-seq
>     (when-let [[f & r] (seq s)]
>       (cons accum (cumulative accum-fn (accum-fn accum f) r))))))
>
> (defn left-total
>  [coll]
>  (map list coll (cumulative + 0 coll)))
>
> I did some microbenchmarking and it does appear to be 2x as fast as
> reductions, and processes the special case left-total just as fast as
> one of the original proposals. Oddly left-tot2 performs very poorly
> though it was claimed to be fast. I suppose this could be yet another
> case of microbenchmarking being evil - but looking at the code the
> reductions version seems to use an atom which implies some unnecessary
> overhead? Or maybe I am missing something important about their
> differences.
>
> I followed the link to the discussion about the original reductions
> and it all seems to be pre-lazy-seq so maybe this is just a case of
> the function should be updated?
>
>

This was discussed before, the new version never made it into a patch:

http://groups.google.com/group/clojure/msg/43de40f078a291cc

Note your use of destructuring in when-let with & makes your
cumulative slightly non-lazy.

Rich

-- 
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

Reply via email to