Neat 0.3.0: Mutable Arrays are a separate type now
I think this is a good idea, but people may disagree. It's gonna allow some refcounter optimizations in the long term, and I think it's just correct as a matter of language semantics. Immutable arrays can be reliably treated as values.
T[]
is now an immutable array. You can append it and append to it, but you cannot change members via index assignment.
T mut[]
is a mutable array. You can append it and append to it, and members can be assigned via a[0] = value
, but it cannot be implicitly converted to a T[]
.
array.freeze
converts a mutable array to an immutable array. It is forbidden to do this when the array still has live references, or to mutate members of the original array after freeze
has been called. (Eventually the language will enforce this.)
Conversely, array.dup
will convert an immutable array to a mutable one.