Very strange bug on Streams and probably compiler

stephane ducasse stephane.ducasse at free.fr
Wed Feb 14 17:32:31 UTC 2007


you can do an optimization (having only one string in the literal  
frame) when this does not impact the semantics of the language.
If strings would be immutable then there would be no problem to have  
only one because we would not see the difference.

>>> 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).
>
> The sharing is not the primary problem, the mutability is.
>
> - Bert -
>
>
>
>




More information about the Squeak-dev mailing list