Yes, this is it. It's isDynamic and metadata getting out of sync. Didn't 
realise the problem has a history going back as far as 1.3.

I don't think it's too urgent to fix (and given the nature of the problem 
any fix may break some code out in the wild. Considering very special and 
rare use cases it may not be worth the hassle.) I have found a workaround 
with Java interop, and I should be good for now.

Thanks for the quick response and clarification.

On Saturday, July 30, 2016 at 1:32:45 PM UTC-7, Alex Miller wrote:
>
> 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 [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
--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to