It's because the value of the + is captured when the partial is created (or when the var is implicitly derefed). The value of the var is implicitly captured (via deref) at the point where it appears in the form.

## Advertising

It's a bit of a complex topic, but this blog post I wrote a few months ago may help a bit: http://blog.cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots On Thu, Dec 1, 2016 at 1:30 PM, Matthew Hamrick <matthewjhamr...@gmail.com> wrote: > I'm confused by the following code. > Could someone explain to me why the def-ed partial has different behavior > to the letted one? > This is especially confusing to me since the #() special form one works as > I expect. > > (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] > > Thanks, > Matt > > -- > 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. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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.