On Wed, Jul 27, 2011 at 2:57 PM, Aaron Cohen <aa...@assonance.org> wrote: > On Wed, Jul 27, 2011 at 2:39 PM, Ken Wesson <kwess...@gmail.com> wrote: >> >> On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen <aa...@assonance.org> wrote: >> > I may be wrong, but don't you need to swap the order of the arguments to >> > f? >> >> You can do that by writing f itself appropriately. Usually either it >> will be a closure or it won't matter (core +, etc.). > > If the order of evaluation doesn't matter, you should probably just be using > reduce in the first place.
True. But the point is that for the likely core functions to use in foldr/reduce, the argument order doesn't matter, so when it does you're likely using a local closure rather than an elsewhere-defined function anyway. It does occur to me, though, that if an operation is commutative, but not associative, then foldr and reduce might give different results even in a case where swapping the function arguments' order doesn't do so. It's just very rare for an operation that's not associative to be commutative. Common math operations for instance are both (*, +), neither (/, -), or associative but not commutative (matrix multiplication, composition of functions), with clojure.core furnishing examples in all three categories (* and +; / and -; comp). -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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