On Mar 8, 6:59 pm, Timothy Baldridge <[email protected]> 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? >
To reiterate what others have said - referencing something that has been def'd is a two-hop lookup. The first is to follow the symbol, through the namespace map, to get the Var instance. This is the part you are concerned about, but it happens at compile-time, so it's all good. The second hop is to follow the pointer that's in the Var. This currently (in 1.2) happens at runtime, but it's pretty cheap (just a pointer deref, I think). In 1.3, this part too will happen at compile- time unless the var is specifically marked as :dynamic. I wonder what will happen in 1.3 with code that does the "declare first" thing: (declare foo) (defn bar [] (do-critical-loop (foo))) (defn foo [] (do-stuff)) Will it suddenly be "slower" (relative to other code). IOW, will it continue to run at 1.2 speeds (presumably "declare" will create a :dynamic var?), while code that puts functions in the "right order" will get magically faster? - Chris -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
