The difference between those two lines is that "x" is a variable binding, "x.a" is a reference inside "x". If the value that the variable"x" is bound to is shared (as when you put it in a set), then modifying "x.a" will modify that everywhere because it modifies the value x is bound to. "x = new" binds x to a new value; this new binding of x is completely separate from it's previous value and does not modify the previous value.
The above is another attempt at explanation. You asked for a rule to memorize, so I'll try to give you one, although it is likely that there are corner cases where understanding will serve you better: 1. Anything of the form <variable name> = <new value> will behave like your example of "t1 = testtype(false)" (does not modify other references) 2. Anything of the form <variable name>.<property name> = <new value> will behave like your example of "t1.v = false" (does modify other references) * Modifying functions (sort!, etc) will follow rule 2; non-modifying functions (sort, etc) will follow rule 1. * Setting array values (a[5] = 2) will follow rule 2, as will setting values in other collections (these are syntactic sugar for setindex!, which is a modifying function) -- Leah On Mon, May 12, 2014 at 7:14 PM, Andrew Dabrowski <unhandya...@gmail.com>wrote: > > So it is OO 101, thanks. > > Note that to a programming naif the difference between > > x.a = new > > and > > x = new > > isn't very perspicuous, but in the first the value of x is modified (old > pointer maintained?) while in the second it is replaced (new pointer?). Is > there a rule of thumb I can memorize so as to able to tell when a > variable's value will be modified and when a new value will be created? Is > it just the use of = as assignment? > >