On Sat, 2012-02-25 at 03:32 -0800, JuanManuel Gimeno Illa wrote: > The source code of reduce is (I've marked in > red the calls than I do not understand).
Please keep in mind that some mail readers are viewing the plain text part, so can't see HTML markup, especially among an audience likely to be using exotic mail readers. > (def > reduce > (fn r First, this is a bootstrapping reduce. Normally: > ([f coll] > (let [s (seq coll)] You could put a `loop' right here, but the implementation of `loop' itself uses reduce! (This has since been changed in core.clj to rename this reduce to a private "reduce1" so its status is clearer.) You could use the bootstrapping loop, but...ugh. With a loop over s here: > (if s > (r f (first s) (next s)) and a `recur' here, you would avoid that extra seq. And the second `seq' follows the fast path out, so is not much worth worrying about. > (next s) == (seq (rest s)) They are semantically equivalent, but implementers of ISeq may provide implementations with different performance characteristics. > Could the same recur call be done using rest? Yes. > What is more idiomatic? Use `next' when you are definitely about to force it with `seq', `empty?', or something anyway, `rest' otherwise. `reduce' qualifies for the former. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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