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.
It's a bit of a complex topic, but this blog post I wrote a few months ago
may help a
Sum-partial-def gets the original + definition because it is evaluated
first, if you want late binding, try (partial reduce (var +)).
On Dec 1, 2016 4:05 PM, "Matthew Hamrick" wrote:
> I'm confused by the following code.
> Could someone explain to me why the def-ed
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 +)
It's a question simply stated with an answer that depends on a lot of
things. And, as is often the case with the person giving an answer, without
asking other people I can only relate it to my own experiences with clojure
and programming in general.
The fun and freeing thing about clojure is the
Hi,
it's almost 8 years later and I am going to ask these same question since
it wasn't really answered
Thanks for taking the time to read. I’m interested in trying out Clojure
> for my first programming language--at least, the first programming language
> in which I intend to commit myself