On Wednesday, October 22, 2014 4:51:23 PM UTC-4, Ambrose Bonnaire-Sergeant 
wrote:
>
> I missed this in the sequence spec <http://clojure.org/sequences>: When 
> seq is used on native Java arrays, changes to the underlying array will be 
> reflected in the seq - you must copy the source array to get full 
> immutability.
>
> I understand the rationale, still quite shocking.
>
> Ambrose
>
> On Wed, Oct 22, 2014 at 3:26 PM, Jozef Wagner <jozef....@gmail.com 
> <javascript:>> wrote:
>
>> Yes, seqs are presented as persistent collections, so this situation
>> is quite unfortunate. But in the case of seq over mutable array, I
>> think practical/performance reasons win over the correctness, which
>> would require caching of realized items.
>
>
As another poster noted, you can get caching of realized items if you 
really really want it, by using (map identity the-array). And if you want a 
snapshot at a particular time you had the array, regardless of how much 
later a particular sequence item will be first consumed, you can copy it 
upfront (with (into [] the-array), or just another array and 
System/arraycopy and don't let a reference to the new array escape). 
Although, mutation *while* you're taking the snapshot is harder to deal 
with. You and the potential mutator would have to agree on an object (say, 
the array itself) to lock. Once you have an immutable object in Clojureland 
though you can dispense with explicit locking and use the STM, atoms, and 
suchlike.

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