On Wed, Dec 30, 2009 at 4:07 AM, Timothy Pratley
<timothyprat...@gmail.com> wrote:
> 2009/12/30 Rich Hickey <richhic...@gmail.com>:
>> This was discussed before, the new version never made it into a patch:
>> http://groups.google.com/group/clojure/msg/43de40f078a291cc
>
> Great!
>
> The 'old' reductions behaves slightly different from the 'new'
> reductions for the 3 argument form:
>    foo=> (reductions + 0 [3 5 10 1 2 7])
>    (0 3 8 18 19 21 28)
>    foo=> (reductions2 + 0 [3 5 10 1 2 7])
>    (3 8 18 19 21 28)
>
> Which output is more correct?

The former.

> On the one hand supplying a preserved
> 'initial value' from outside does not make much sense, but on the
> other hand perhaps it is more in step with 3 argument reduce.
>
> Does it matter? Probably not. It does provide an interesting case
> study. The 3 argument form could be considered just a helper to
> achieve the 2 argument form, but because it is part of the public
> interface people may chose to rely on it:
>    (defn left-total3 [coll]
>     (map list coll (reductions + 0 coll)))
> might have been better written as
>    (defn left-total3 [coll]
>     (map list coll (cons 0 (reductions + coll))))
> So is exposing the 3 argument version a bad thing? It is not very
> idiomatic to use the alternatives:
> (let-fn [(reducer [f acc coll] ...)]
>  (defn reductions [f coll]  ... reducer ...))
> And then again if I can call (reduce + 3 [1 2]) maybe it is reasonable
> to call (reductions + 3 [1 2])
> I'm over analyzing what is really a non-issue, but just found it
> thought provoking.
>
> Back to more practical concerns, attached is a modified version for
> consideration which preserves the old behavior but is faster. Happy to
> supply a git patch if on the right track - let me know what is best :)
>
>

Great - thanks.

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