From: Phil Meier Date: 2007-09-18T16:15:04+09:00 Subject: Re: The meaning of a = b in object oriented languages Lloyd Linklater schrieb: > SpringFlowers AutumnMoon wrote: >> Is that the case: if a is an object, then b = a is only copying the >> reference? > > That and it adds a counter. I do not see the evidence of a counter. > a = ["foo", "bar"] that means, a points to the array object (with two elements). > b = a Now b also points to the same array object as a. > b[0] = "bite me" Element 1 (with index 0) get's changed - and since a and b both point to this array object, the changes are seen by both variables (a and b). > p a, b > > a = "different" Now - a points to another object (of type string) then b. That the whole magic, i.e. no magic at all and no counter needed. > p a, b > > *** > > In the first print, we get > ["something else", "bar"] > ["something else", "bar"] > > showing that changing b changes a, as expected. However, if we change > a, b is NOT changed as seen in the second print. b is NOT changed because we did not change b and we also did not change the array object b points to. > > "different" > ["something else", "bar"] > > That means that there is a counter inside that says to separate the two > or b would have changed with a as a changed with b initially. This is not true. There is no need of any counter. BR Phil