Description
This is a feature request.
I'm implementing a package where I have a container of arrays. This is meant to be used in a mult-threaded context, and tracking mutability/ummutability is very relevant.
I tried using ReadOnlyArrays
and run into the issue JuliaArrays/ReadOnlyArrays.jl#2 where @bkamins made the point that Julia doesn't have a concept of immutable collections - this applies to Array
, Dict
, etc.
This seems like an unfortunate oversight. Tracking mutable vs. immutable collections is important for correct code in general, and even more so when dealing with multi-threaded code, which is becoming ever more relevant with today's multi-core hardware.
Granted that for quick-and-dirty scripts people should be able to to just hammer out some short piece of working code, without distractions from the language or the standard libraries. However, for more serious code bases it seems like it would make sense to at least provide an option to "freeze" a collection against further modifications - similarly to how type annotations are optional today.
As a precedence, Python provides a writeable
flag in its Numpy ndarray
type. The equivalent in Julia would be to add a few functions such as isfrozen
, freeze!
, unfreeze!
to the standard collections API.