Here's some broken code:
struct NumberedList
index::Int64
values::Vector{Int64}
NumberedList(i) = new(i, Int64[])
end
function set_values!(list::NumberedList, new_values::Vector{Int64})
list.values = new_values
end
# ---
mylist = NumberedList(1)
set_values!(mylist, [1, 2, 3])
I don't want to do either of these:
- I could declare the
NumberedListas amutable struct(making everything mutable) - I could replace
set_values!with something like this (copy all the values):
function set_values!(list::NumberedList, new_values::Vector{Int64})
for i in new_values
push!(list.values, i)
end
end
But I'd like to make index immutable, but allow values to be assigned to.
Other notes:
- Thread from the Discourse: "Mutable field in immutable type," but this doesn't apply to vectors in this setting.