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.wag...@gmail.com>
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.
>
> Jozef
>
> On Wed, Oct 22, 2014 at 7:51 PM, Ambrose Bonnaire-Sergeant
> <abonnaireserge...@gmail.com> wrote:
> > Sorry, to be specific I'm disturbed by the apparent mutation of an
> immutable
> > data structure after it has been observed!
> >
> > Thanks,
> > Ambrose
> >
> > On Wed, Oct 22, 2014 at 12:52 PM, Jozef Wagner <jozef.wag...@gmail.com>
> > wrote:
> >>
> >> Not every ISeq is lazy. In this case the seq is not lazy but is backed
> by
> >> a mutable array, thus the mentioned behavior.
> >>
> >> Jozef
> >>
> >> On Wednesday, October 22, 2014 6:41:34 PM UTC+2, Fluid Dynamics wrote:
> >>>
> >>> On Wednesday, October 22, 2014 12:10:30 PM UTC-4, Ambrose
> >>> Bonnaire-Sergeant wrote:
> >>>>
> >>>> On Wed, Oct 22, 2014 at 9:32 AM, Fluid Dynamics <a209...@trbvm.com>
> >>>> wrote:
> >>>>>>
> >>>>>> and is guaranteed to always produce the same value for the same
> field.
> >>>>>
> >>>>>
> >>>>> Nope:
> >>>>>
> >>>>> => (def foo (int-array [1 2 2 5 9 3]))
> >>>>> #'user/foo
> >>>>> => (def bar (seq foo))
> >>>>> #'user/bar
> >>>>> => bar
> >>>>> (1 2 2 5 9 3)
> >>>>> => (aset foo 3 3)
> >>>>> 3
> >>>>> => bar
> >>>>> (1 2 2 3 9 3)
> >>>>>
> >>>>
> >>>> What is happening here? (seq foo) certainly does not look like
> something
> >>>> that should extend ISeq from its behaviour.
> >>>
> >>>
> >>> => (instance? clojure.lang.ISeq bar)
> >>> true
> >>>
> >
>

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