On Mon, Mar 26, 2012 at 4:03 PM, Daniel Solano Gomez
<cloj...@sattvik.com> wrote:
> On Mon Mar 26 15:15 2012, Cedric Greevey wrote:
>> > What you're running into is the overhead of get the root value of vars
>> > like swap! and move-up!.  The only way to avoid this is use something
>> > like definline.
>>
>> I thought that in 1.3 those had been made much faster to access if
>> they didn't have ^{:dynamic true} applied to them?
>
>
> As of Clojure 1.3, by default, vars only have a root value that exists
> globally.  When you tag a var as being ^:dynamic, it is allowed to have
> thread-local bindings.  However, remember you can always change the
> value of a var:
>
> (defn foo [] :foo) ; evaluates to :foo
>
> (defn printfoo [] (println (foo)))
>
> (printfoo) ; prints :foo
>
> (defn foo [] :bar) ; evaluates to :bar
>
> (printfoo) ; prints :bar
>
> As a result, whenever you use a var in a function, the latest value is
> retrieved from the var.  This ensures that your function always sees the
> latest value that is assigned to the var.

Yes, but that's only one step of indirection. It shouldn't be anywhere
near as slow as accessing a ThreadLocal and nearly as fast as using a
true constant.

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