I think you've explained it well. You can 
use 
https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/completing 
to patch in a better completion arity for - (here I think identity is what 
you want and that is the default for completing):

(transduce xf (completing -) 0 (range 10))
 



On Monday, January 25, 2016 at 7:12:42 AM UTC-6, Mark Tinsley wrote:
>
> Hi all,
>
> Could I have some clarification on something, I know how to solve the 
> issue I just want to make sure I understand the reasons behind it, given 
> the following:
>
> (def xf
>   (comp
>    (filter odd?)
>    (map inc)
>    (take 5)))
>
>
> (transduce xf + 0 (range 10))
>
> I get the answer: => 30
>
> Makes sense, now if I do this:
>
> (transduce xf - 0 (range 10))
>
> I get the answer.... => 30
>
> But... 
>
> (reduce - 0 (eduction xf (range 10))) 
>
> gives => -30
>
> I can see why this is, looking at 
> https://github.com/clojure/clojure/blob/010864f8ed828f8d261807b7345f1a539c5b20df/src/clj/clojure/core.clj#L6587
>  
> the binding ret in the let has the reduced value. This is then passed to 
> the reducers arity-1 function, which preforms something equivalent to the 
> following (- -30) to give 30.
>
> The reason for the arity-1 function is to complete/cleanup state as seen 
> in the partition-all function 
> https://github.com/clojure/clojure/blob/010864f8ed828f8d261807b7345f1a539c5b20df/src/clj/clojure/core.clj#L6954
>
> As '-' historically had an arity-1 function we cannot update the 
> behaviour, this may well be the case for other functions. 
>
> Am I right in the above or am I missing something? 
>
> Thanks,
>
> Mark
>
>
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to