On Fri, Oct 30, 2009 at 9:31 PM, Josh Daghlian <daghl...@gmail.com> wrote:

> During the Boston Lisp Users meeting last November (?) I asked Rich
> about whether seq's on mutable java.util.Collections were really
> immutable if the underlying object (the Collection) was mutable. He
> emphatically said that no, the seq is still immutable, and that it
> caches values as it sees them. I just checked, and for ArrayList it
> still works like Rich said:
>
> user> x
> #<ArrayList [foo, bar, baz, quux]
> >
> user> (def y (seq x))
> #'user/
> y
> user> (first y)
> "foo"
> user> (.add x 0 "zzz")
> nil
> user> x
> #<ArrayList [zzz, foo, bar, baz, quux]
> >
> user> (first y)
> "foo"
> user>
>
> I am surprised that the same doesn't happen with java arrays. Sounds
> like a bug, or at least a change request I'd second.
>

Interesting.

I thought maybe inserting at the start might not affect the seq even if the
maybe-bug did affect ArrayList, because it might just stay aligned with the
existing elements. But no:

user=> (def x (ArrayList. ["foo" "bar" "baz" "quux"]))
#'user/x
user=> x
#<ArrayList [foo, bar, baz, quux]>
user=> (def y (seq x))
#'user/y
user=> (first y)
"foo"
user=> (.set x 0 "boo")
"foo"
user=> (first y)
"foo"
user=> (first x)
"boo"

So, (first y) doesn't morph even if you mutate the first cell of the
ArrayList in place.

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