On Thursday, December 13, 2012 4:14:23 AM UTC-8, Marshall 
Bockrath-Vandegrift wrote:

> kristianlm <kris...@adellica.com <javascript:>> writes: 
>
> > I'm enjoying testing Java code with Clojure and it's been a lot of fun 
> > so far. Coming from Scheme, the transit is comfortable. However, I 
> > encountered a big surprise when I nested def's and used them with a 
> > proxy: 
>
> This is a common surprise for people with previous exposure to Scheme: 
> `def` in Clojure is always explicitly namespace-scoped.  What it does is 
> create a var with a name and intern it into the namespace with that 
> name, not introduce a name in the current lexical scope.  Nested `def`s 
> are thus very rarely going to be what one actually want, and the 
> behavior you’re seeing is exactly what one would expect. 
>
>
To further clarify: the mew* version doesn't *actually* behave just like 
new-let*, although it usually will have the same consequences. The issue is 
that there's a race condition if two different threads call mew* at the 
same time: they might both mutate i, then both read it, and thus end up 
with the same reference. Really, as Marhsall says, a nested def is (almost) 
never what you want. 

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