In julia functions : passed by reference or value?
I think the most rigourous answer is the one in
Julia function argument by reference
Strictly speaking, Julia is not "call-by-reference" but "call-by-value where the value is a reference" , or "call-by-sharing", as used by most languages such as python, java, ruby...
The corresponding terms in Julia are mutable and immutable types:
immutable objects (either
bitstype
s, such asInt
or composite types declared withimmutable
, such asComplex
) cannot be modified once created, and so are passed by copying.mutable objects (arrays, or composite types declared with
type
) are passed by reference, so can be modified by calling functions. By convention such functions end with an exclamation mark (e.g.,sort!
), but this is not enforced by the language.
Note however that an immutable object can contain a mutable object, which can still be modified by a function.
This is explained in more detail in the FAQ.