Am 2010-09-27 um 10:32 schrieb Johan Brichau:
I convinced the teacher who will be taking over my Smalltalk courses at UCLouvain (starting this week) to use Pharo :-) One of the introductory exercises in these courses shows the difference between '==' and '='. However, in Pharo (&Squeak) the following goes wrong imho:
'a' == 'a' -> true $a asString == $a asString -> false
It seems that when you evaluate the expression, the (semantically identical) strings are represented as the same literal in the compiled block. For example, try to evaluate the following code by evaluating each statement in a separate doit. Then do it again as a single block...
|a b| a := 'a'. b := 'a'. a == b inspect
Do I make it an issue? Is there already an issue? (did not find one) Am I wrong?
I think this is a compiler optimization, as strings in general are immutable if created via literal notation (afaik). Remember that most operations on strings create copies of the original string. It gets even more interesting: Look at doit1.png I've referenced to 'abs' four times in the doit, nevertheless, there is only one literal stored. When i execute the second line, i operate with the #at:put: directly on that literal (doit2.png). hence, the method does not return 'abs' but 'ads' (as you can see by the 'stack top' in doit3.png) HTH, So Long, -Tobias