From: Gary Wright Date: 2007-09-19T03:58:11+09:00 Subject: Re: The meaning of a = b in object oriented languages On Sep 18, 2007, at 1:50 AM, Russell Wallace wrote: > Summercool wrote: >> so most or all object oriented language do assignment by reference? >> is there any object oriented language actually do assignment by >> value? I kind of remember in C++, if you do >> Animal a, b; >> a = b will actually be assignment by value. >> while in Java, Python, and Ruby, there are all assignment by >> reference. ("set by reference") >> Is that the case: if a is an object, then b = a is only copying the >> reference? > > Yes, your understanding is exactly correct; C++ will assign by > value unless you explicitly use pointers, but the other languages > will assign by reference (except for primitive types). I don't think you can generalize assignment semantics. You have to consider each language separately. With respect to "primitive types" and Ruby, it isn't necessary to make exception for these types with respect to assignment semantics. All variables hold object references and assignment is always in terms of references. This is true for all objects (including symbols, fixnums, true/false/nil). The only thing special about Ruby's 'primitive' classes is that they behave such that identity is isomorphic to equality. That is to say that a.equal?(b) if and only iff (a == b). Gary Wright