vec with a short array of objects is a special case in that it simply puts the existing array in a PersistentVector wrapper:
user=> (def arr (object-array 16)) #'user/arr user=> (doseq [i (range 16)] (aset arr i i)) nil user=> (def v (vec arr)) #'user/v user=> v [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] user=> (aset arr 0 :foo) :foo user=> v [:foo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] This works for up to 32 objects, as that is the number that fits in a PV tail. No member access syntax here -- not sure if object-array/aset count as interop. NB. vec's docstring is explicit about this. On 7 May 2014 02:35, Andy Fingerhut <[email protected]> wrote: > Alex, I may be unfamiliar with the definitions of truly immutable and > effectively immutable being used here, but if I can mutate the contents of a > Java Object array that is a final field after an object is constructed, does > it really matter that much if it is final? It is trivially easy to mutate > using Java access. Here is the example that I mentioned earlier in this > thread, copied here for convenience: > > user=> (def v [1 2 3]) > #'user/v > user=> (class v) > clojure.lang.PersistentVector > user=> v > [1 2 3] > user=> (aset (.tail v) 1 -2) > -2 > user=> v > [1 -2 3] > > Andy > > > On Tue, May 6, 2014 at 4:49 PM, Alex Miller <[email protected]> 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 [email protected] >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> [email protected] >> 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 [email protected]. >> For more options, visit https://groups.google.com/d/optout. > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > [email protected] > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
