This is a short summary based on what I understood from documentation, and this long thread , without mixing in (much of) scope rules, or any implementation details.
I will appreciate if somebody could check it’s validity.
Given that expr is either an expression evaluating to (returning) an object, or a literal object, either mutable or immutable, and not just a name ;
f(y) = do_with(y)
x=expr makes the name/variable
xbind to a new object (with new “reference” hence new identity). (even though “reference” can’t be retrieved in Julia for immutable objects)
ybind to the same object as
xis bound to (with same “reference” hence same identity)
- “reference” is a semantics-level concept that ensures that when 2 variables have same reference to an object (thus “share” the same object), and the object is mutable, then mutations produced via one variable are going to be seen when the object is retrieved via the other variable.
- The above about
y=xis true not only when
yare in same scope, but also when
x-s scope is the parent scope of
y's scope, regardless of
x-s scope being local or global
Comment: For the sake of ease of learning/understanding, I wish Julia offered a way to check the “reference” of even immutable objects.