You cannot modify the components of an immutable type but if a component is mutable you can modify the components of this component. Thus:
julia> struct A; x; end
julia> mutable struct B; y; end
julia> a=A(B(3))
A(B(3))
julia> a.x = B(7) # Bad! Cannot redefine a component (x here) of an immutable struct
ERROR: setfield!: immutable struct of type A cannot be changed
Stacktrace:
[1] setproperty!(x::A, f::Symbol, v::B)
@ Base ./Base.jl:39
[2] top-level scope
@ REPL[6]:1
julia> a.x.y = 7 # Good! Redefinition of components of a.x (a mutable struct) is OK
7
Similarly, if you go back to your original example, you cannot redefine myCrystal.nBasis but you can redefine the components of myCrystal.nBasis. That is, this is OK:
myCrystal.nBasis[1] = 1
myCrystal.nBasis[2] = 4
myCrystal.nBasis[3] = 8
which is equivalent to myCrystal.nBasis .= [1,4,8].
Notice that trying to change the size of the vector of myCrystal.nBasis is not possible due to the immutability of the crystal struct.
From the manual Types · The Julia Language
- For composite types, this (immutability) means that the identity of the values of its fields will never change. When the fields are bits types, that means their bits will never change, for fields whose values are mutable types like arrays, that means the fields will always refer to the same mutable value even though that mutable value’s content may itself be modified. (emphesis added)