identity and equivalence in Squeak

tblanchard at mac.com tblanchard at mac.com
Thu Feb 13 16:41:00 UTC 2003


You're being thwarted by a clever compiler.
To save space the compiler merges equivalent string literals into a 
single string.

Try:
(String withAll: 'aaa') = (String withAll: 'aaa')
(String withAll: 'aaa') == (String withAll: 'aaa')

Or to play with symbol equivalence send each side an asSymbol.


On Thursday, February 13, 2003, at 05:08  PM, shane at shaneroberts.com 
wrote:

> I am learning Squeak (and Smalltalk) for the first time,
> and I am reading Stephane Ducasse's forthcoming book on
> Squeak, "Learning Programming in Squeak".
>
> Section 5.2 of Chapter 1 discusses  equivalence and identity
> of strings and symbols in Squeak.
>
> In a Workspace window I am doing a printit ( Alt-p ) of the
> following lines:
>
> 'aaa' == 'aaa'
> 'aaa' = 'aaa'
> #aaa == #aaa
> #aaa = #aaa
>
> which produces:
>
>
> 'aaa' == 'aaa' true
> 'aaa' = 'aaa' true
> #aaa == #aaa true
> #aaa = #aaa true
>
> I thought the first line should produce:
> 'aaa' == 'aaa' false
>
> since 'aaa' and 'aaa' are equal but not identical (not the same
> object).  Or perhaps they are, in the compiler?
> Since they are the same literal constants.
>
> The book says to try these but does not say what the results should
> be.
>
> On the other hand:
>
> a := 'aaa'
> b := 'aaa'
> a = b
> a == b
>
> produces:
>
> a = b false
> a == b false
>
> I thought:
> a = b
>
> should produce:
> a = b true
>
> because a and b are equal (for string comparison) though not
> identical (the same object).
>
> Can anyone tell me what I am missing here?
>
> The book says:
> "Try: ’aaa’ == ’aaa’ and #aaa == #aaa."
>
> Thanks,
> Shane
>
>



More information about the Squeak-dev mailing list