Consider this ordinary way of defining a dynamic variable:
user=> (def ^:dynamic *dynamo* 3)
As you'd expect, you can rebind:
user=> (binding [*dynamo* "new value"] *dynamo*)
"new value"
The metadata tells you why:
user=> (meta #'*dynamo*)
{:ns #<Namespace user>, :name *dynamo*, :dynamic true, :line 1, :file ...}
Now let's make another variable with `intern`, copying the metadata from
`*dynamo*`:
user=> (intern *ns* (with-meta '*copy* (meta #'*dynamo*)) *dynamo*)
Same metadata (except for the name):
user=> (meta #'*copy*)
{:ns #<Namespace user>, :name *copy*, :dynamic true, :line 1, :file ...}
But you can't rebind:
user=> (binding [*copy* "new value"] *copy*)
IllegalStateException Can't dynamically bind non-dynamic var: user/*copy*
clojure.lang.Var.pushThreadBindings (Var.java:339)
Bug?
-----
Brian Marick, Artisanal Labrador
Now working at http://path11.com
Contract programming in Ruby and Clojure
Occasional consulting on Agile
--
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