identity in Squeak
Andrew C. Greenberg
werdna at mucow.com
Tue Jun 18 01:19:50 UTC 2002
On the other hand, if you execute
foo _ 'foo'.
foo == 'foo'
by selecting BOTH lines so they are compiled together, you will get the
opposite result.
On Sunday, June 16, 2002, at 07:21 PM, Martin McClure wrote:
> At 10:55 AM -0700 6/15/02, nicola farina wrote:
>> hi all,
>> just one question:
>>
>> why in Squeak evaluating the command
>> 'fooBar' == 'fooBar'
>> returns true (as if were Symbols)?
>
> You are correct that Symbols are guaranteed to be identical if they're
> equal, and that Strings are not guaranteed to be equal. But they're not
> guaranteed to be not equal, either.
>
> In Smalltalk, Strings are mutable, their characters can be changed with
> messages such as at:put:. However, literal strings are treated as
> though they are immutable, because changing them is a very bad idea.
> Some Smalltalks (VisualWorks 7, for instance) enforce the immutability
> of literal strings.
>
> Squeak does not enforce immutability, but it does assume that literal
> strings will not be changed, so if it sees two equal literal Strings in
> the same compilation unit it only creates one String object to save
> space. The compilation unit in Squeak's current implementation is the
> method, so if you create two equal Strings in separate methods you will
> find that they are *not* identical.
>
> For instance, try evaluating this in a workspace:
>
> foo _ 'foo'
>
> Then evaluate:
>
> foo == 'foo'
>
> It will return false.
>
> -Martin
>
More information about the Squeak-dev
mailing list
|