Very strange bug on Streams and probably compiler

stephane ducasse stephane.ducasse at free.fr
Wed Feb 14 15:56:56 UTC 2007


Bert

> It is normal.

No this is not. You get used to it and accept it.
>
> You are modifying the 'a test ' literal into 'to test'. This  
> modified string gets copied in the second test.
>
> Lesson: never modify string literals.

It shows that the fact that the compiler optimizes the use of certain  
literals such as boolean and number is good
for immutable objects but is wrong for mutable object such as strings.

Iin the semantics of Smalltalk nothing says that two strings with the  
same representation in the same
methods are pointing to the same object. I did not check in which  
books but the difference between strings and symbols
is really that two strings are pointing to two different objects,  
while symbols are referring to the same objects (and are immutable).

Stef



More information about the Squeak-dev mailing list