Modifying vector in an immutable

question

#1

When an immutable has a Vector field, is it allowed to modify that using ! functions (like these)? My understanding is that even if the underlying memory is remapped (eg because the vector grows or shrinks too much), it is still the “same” vector, so it is OK. MWE:

immutable Foo
    v::Vector
end
foo = Foo([])
push!(foo.v, 1)

#2

It is still the same julia object. This is perfectly fine.


#3

Note that you (almost) always want to strictly type fields in a type definition:

immutable Foo
    v::Vector{Float64}
end

or parametrically:

immutable Foo{T}
    v::Vector{T}
end

#4

Definitely — I was just keeping the example minimal.