Yes, this is how julia works. After you do
x = [1, 2]
Sa = S(x)
x
and Sa.f
are the same vector in that they occupy the same physical memory. See also this post for an explanation of this (you can think of A
and B
in that post as your x
and S.f
).
If you want your type S
to make a copy of the input you can define an inner constructor that copies:
mutable struct S
f::Vector{Int}
S(x) = new(copy(x))
end