I think there are differences here due to the two mechanisms for treating a 
Var as dynamic. This reminds me of the 
ticket http://dev.clojure.org/jira/browse/CLJ-859 as well. I'm not sure 
what the proper resolution should be as there are several ways to go with 
it.


On Saturday, July 30, 2016 at 3:20:16 PM UTC-5, Yuri Steinschreiber wrote:
>
> Hello -
>
> The documentation specifies that 'def' and 'intern' have the same behavior 
> with regards to metadata on the Var they define/intern. So I expected these 
> to be equivalent:
>
> (def ^:dynamic my-var)
>
> (intern *ns* (with-meta 'my-var {:dynamic true}))
>
> Indeed, (meta #'my-var) correctly show :dynamic true in either case.
>
> However,
>
> (binding [my-var :foo] my-var)
>
> throws an exception in the case of intern usage, complaining that the Var 
> is non-dynamic.
>
> The analysis of Clojure source reveals that 
> clojure.lang.Var/pushThreadBindings checks a member isDynamic, rather than 
> the metada itself. Which is understandable from the performance point of 
> view. Problem is the Var's property isDynamic is set by 'def' special form 
> only, while 'intern' doesn't do it.
>
> Am I correct in thinking that either the doc needs to be updated to 
> reflect a special status of 'def' in regard to dynamic Vars, or 'intern' 
> has a bug?
>
> I personally think its a bug in 'intern'. It can be circumvented by using 
> Java interop on the Var, like (.setDynamic #'my-var) after interning it, 
> but it looks ugly.
>
> The reason I stumbled on it is I need to intern a dynamic Var in a macro, 
> and using 'def' in a macro doesn't seem to quite work with metadata - it's 
> apparently being processed by the reader at a wrong time (maybe I'm missing 
> something, but that's a question for another day.) I tried to use 'intern' 
> instead and hit the problem described above.
>
> Cheers.........................Yuri
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to