On Mar 8, 3:59 pm, Timothy Baldridge <tbaldri...@gmail.com> wrote:
> If in a namespace I bind a var:
>
> (def foo 3)
>
> And then later on in my program re-bind that var:
>
> (def foo 1)
>
> Will all parts of my program instantly see that update? How is it
> possible to have any sort performance when we're basically having a
> namespace function lookup for every single function call?
>
> Thanks for the help,
>
> Timothy
>
> --
> “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)

That's not a binding, it's a def - they are different things. And yes,
it slows things down a bit, so in 1.3 the default is to not support
rebinding (though re-def'ing is still supported). But are you really
asking how it's possible to have "any sort of performance" because a
function call requires a pointer dereference? #'foo is a var whose
current value is 3; #'first is a var whose current value is
clojure.core/first. The compiler knows you're referring to #'first,
and doesn't have to do any lookups to get to the pointer; it does a
single deref to get the value of that pointer, just like it does to
see what value is held in a function parameter (since those are passed
by pointer). This is not that expensive.

By the way, re-def'ing at runtime is a pretty bad code smell. If
you're actually doing this, look into whether you can improve your
code somehow, eg with one of: binding, atom/ref, or a closure
capturing the value you want to "set".

-- 
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

Reply via email to