True! Hash codes are a special case - the pattern they use is sometimes 
called the "racy single-check idiom" and is discussed in Effective Java in 
Item 71 or on an internet near you. The canonical example of this is 
java.lang.String. The trick is that if you don't have a non-0 hash code, 
compute it yourself and stash it. If threads happen to see it, they can use 
it! If they don't see it, they compute it themselves. If two threads race, 
they write the *same* value, so everyone is fine. One important aspect is 
that the hash code must be an int which can be written atomically; if it 
was a long, you'd potentially be subject to long tearing.  

As of Clojure 1.6, Symbols also use this idiom for hasheq. Keywords do not 
- the assumption with keywords is that they are likely to be used as keys 
and so the hasheq is pre-computed and cached during construction (but 
keywords are re-used so this is only done once per keyword).


On Tuesday, May 6, 2014 7:07:37 PM UTC-5, tbc++ wrote:
>
> And hash codes are not final as they are calculated on-the-fly on most of 
> the Clojure data structures. 
>
> Timothy
>
>
> On Tue, May 6, 2014 at 5:49 PM, Alex Miller <al...@puredanger.com<javascript:>
> > wrote:
>
>> The Clojure persistent data structures are truly immutable - all fields 
>> are final and referred objects are not mutated after construction so that 
>> freeze occurs.  One obvious exception are the transient variants (
>> http://clojure.org/transients). You can look at the code in 
>> https://github.com/clojure/clojure/tree/master/src/jvm/clojure/lang - 
>> any of the Persistent*.java.
>>
>>
>> On Tuesday, May 6, 2014 4:11:49 PM UTC-5, Mike Fikes wrote:
>>>
>>> Are the persistent immutable data structures in Clojure "truly" 
>>> immutable (using final fields, relying on constructor freezing), or are 
>>> they mean to be merely effectively immutable (as defined in JICP)?
>>>
>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com<javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> 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+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> “One of the main causes of the fall of the Roman Empire was that–lacking 
> zero–they had no way to indicate successful termination of their C 
> programs.”
> (Robert Firth) 
>

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