Phil, that's an interesting point.

Consider (def x (cons (new java.util.Date) ()))

The object identified by x is *mutable*, but if the contained Date will not 
be modified by the program, then the resulting object can be treated as 
*effectively 
immutable, *as you pointed out.

But, it would seem that you could pass x to another thread without 
synchronization, and then safely read the contained Date instance by that 
thread, because it has been safely published by virtue of having been 
conveyed by a final field of the Cons instance. Of course, you would run 
into trouble if you took that Date instance and passed it directly to 
another thread without synchronization.

In other words, you could step outside of the limited profile of the Java 
memory model that JCIP prescribes treating x as something (useful) between 
*effectively 
immutable *and *immutable, *with the end result being that you can treat x as 
being *immutable.*

On Wednesday, May 7, 2014 7:13:31 AM UTC-4, Phillip Lord wrote:
>
>
> Since the data structures and interfaces, they are effectively 
> immutable. 
>
> Consider this: 
>
> final public class Cons extends ASeq implements Serializable { 
>
> private final Object _first; 
> private final ISeq _more; 
>
> public Cons(Object first, ISeq _more){ 
>         this._first = first; 
>         this._more = _more; 
> } 
> } 
>
> Although Cons uses final fields and constructor fields, "_more" is an 
> ISeq; given that this could be mutable, so could cons. 
>
> Phil 
>
> Mike Fikes <mike...@me.com <javascript:>> writes: 
>
> > 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)? 
>
> -- 
> Phillip Lord,                           Phone: +44 (0) 191 222 7827 
> Lecturer in Bioinformatics,             Email: 
> philli...@newcastle.ac.uk<javascript:> 
> School of Computing Science,            
> http://homepages.cs.ncl.ac.uk/phillip.lord 
> Room 914 Claremont Tower,               skype: russet_apples 
> Newcastle University,                   twitter: phillord 
> NE1 7RU                                 
>

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