(def sum-partial-def (partial reduce +))
(let [sum-partial (partial reduce +) sum-# #(reduce + %1) nums [1 2 3 4]] [(sum-partial-def nums) (reduce + nums) (sum-# nums) (sum-partial nums)]) ;; => [10 10 10 10]
(with-redefs [+ (fn [a b] (.add (.add (BigInteger. (str a)) (BigInteger. (str b))) (BigInteger/ONE)))] (let [sum-partial (partial reduce +) sum-# #(reduce + %1) nums [1 2 3 4]] [(sum-partial-def nums) (reduce + nums) (sum-# nums) (sum-partial nums)])) ;; => [10 13 13 13]
Sum-partial-def gets the original + definition because it is evaluated first, if you want late binding, try (partial reduce (var +)).
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.