identity and equivalence in Squeak

diegogomezdeck at consultar.com diegogomezdeck at consultar.com
Thu Feb 13 16:40:53 UTC 2003


Hi Shane,

Two equal Strings in the SAME method become a unique instance.

This is an optimization made by the compiler.

Diego

> 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