I have the impression that the point of the initial question was lost in this thread, spinning into mutability, etc.
Let me try to phrase it in another way:
'foo' = 'foo' true "ok" 'foo' == 'foo' true "NOT OK"
The underlying reason is that whenever I execute one of these expressions in a workspace, a method is created behind my back and then executed. In the case of comparing two strings, the compiler creates *a single literal for both strings*. This is plain wrong: a string is a collection of characters, and therefore these are two different instances of this collection that happen to have the same contents.
Now some more experiments:
Take any class (say a new class A). First add the following two methods:
foo ^'foo'
foo2 ^'foo'
Now execute the following code: A new foo == A new foo "true ?!?!?!?!?!?!" A new foo == A new foo2 "false"
To top it all of, add one more method:
isIdentical: arg1 to: arg2
^arg1 == arg2
So consider the following now: A new isIdentical: A new foo with: A new foo2 "false" A new isIdentical: 'foo' to: 'foo' "true"
I can only conclude that this is really not what you want.....
On 14 Feb 2007, at 14 February/18:33, stephane ducasse wrote:
Do you have example? Because VW introduced immutable objects and I would like to educate my taste on this topic.
On 14 févr. 07, at 17:03, Lukas Renggli wrote:
Lesson: never modify string literals.
Ohh god, how much I wish to have immutability on a per object bases.
Cheers, Lukas
-- Lukas Renggli http://www.lukas-renggli.ch