On Jan 9, 2013, at 12:37 AM,
wujek....@gmail.com wrote:
> Hi. I am currently learning clojure, which is a nice experience, but you all know that.
> I have question about certain metadata definitions, which I couldn't find a straight answer to on the net, and in none of the books I'm reading:
> 1. is ^:dynamic the same as ^{:dynamic true}, just a shortcut?
Yes.
> 2. is (def ^:dynamic ^:blah x) the same as (def ^{:dynamic true :blah true} x)?
Yes.
> My tests show that the answer to the first 2 questions is yes, but I can't seem to find anything that would back that up.
I don't know where else this might be documented, other than the Clojure source code, but one place is on the Clojure cheatsheet, in the section called Metadata, subsection "Abbrevs" for "Abbreviations":
http://clojure.org/cheatsheet
http://jafingerhut.github.com
There you will also see that ^String is an abbreviation for ^{:tag String}, and in general ^Type for ^{:tag Type}
> 3. why so many ways to do the same?
Clojure developers thought it would be nice to have shorter ways to write metadata expressions that simply set a key's value to true, or annotated the type, since those are quite common cases.
I am not sure about the answers to the questions below off-hand. Hopefully someone else can address them.
Andy
> 4. what does ^:static do? I read on SO that it is not used any more, but the source code in clojure.core still has these, and various tutorials use them as well.
> 5. since when does one need to use ^:dynamic on vars to be able to use (binding [...]) to rebind them thread-locally? Clojure in Action has a nice example of a simple mocking framework that uses this feature but without dynamic, but it is about clj 1.2 I think. 1.3 seems to require it though.
>
> Regards,
> wujek