Hi,

Am 20.10.2011 um 19:53 schrieb Micah Martin:

> I recently tried to get Speclj running on Clojure 1.3 and came across the 
> following problem:
> 
> (list
>  (declare ^:dynamic p)
>  (defn q [] @p))
> 
> (binding [p (atom 10)]
>  (q))
> 
>> java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to 
>> clojure.lang.IDeref
> 
> Thanks to @cemerick for helping me condense the snippet, and thanks to both 
> @cemerick and @chouser for the lively discussion on IRC.  Yet the discussion 
> was inconclusive.  Is the above expected behavior? 

I'm not sure. Maybe it's undefined? Clojure compiles per top-level form. In 
this case this is the call to list. However in p does not exist before. It is 
created by the def inside this form. And maybe I'm just a weenie, but I 
wouldn't bet on some not very well documented peculiarities of def.

>From the “one top-level form” rule do is an exception. And indeed this seems 
>to be for a reason:

user=> (do (declare ^:dynamic p) (defn q [] @p))
#'user/q
user=> (binding [p (atom 10)] (q))
10

So maybe the rule of thumb is: never reference defs made in the same top-level 
form unless this form is a do.

I'm sorry. I can't explain things further. I suspect that the effect you see is 
due to some accidental, implementation-dependent behavior of the compiler.

Sincerely
Meikel

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