[BUG] equivalence between strings and symbols

Dan Ingalls Dan.Ingalls at disney.com
Tue Apr 11 04:59:58 UTC 2000


Stephan Rudlof wrote:
> >What about completely *removing* Symbol>>= ?
> >
> >Has anybody tried this (without changing other methods)?

Now, Stephan, the true Squeaker does not ask such a question ;-).

When in doubt, try it out.

I did, and everything seems reasonably happy.  Meaning that I removed that one method, then recompiled the whole system, and everything seems to work as before.  We should, of course, expect it to.  If two symbols were == before, they should be = after.  If they were not == before, they should not be = afterward.

I say "reasonably" because I have not timed anything yet.  There can be no doubt that = runs slower than == between large strings.  Next time I will time a recompilation of the system before and after -- this should be a good test, since the compiler works fairly heavily with Symbols.

> >Then
> >	#abc = 'abc'
> >	'abc' = #abc
> >should both be true; and
> >	#abc == 'abc'
> >	'abc' == #abc
> >should both be false.

I much prefer this approach to that of legislating against =-ity between behaviorally identical objects.

Allen_Wirfs-Brock commented...
>The ANSI Standard was trying to allow for this possibility. I think it 
>succeeded in allowing this.
>
>Java also essentially takes the above approach. There is only a single 
>String class. The intern() method of a String returns a unique "canonical" 
>instance of the String that corresponds to the receiver.  Thus such a 
>canonical string has essentially the same semantics as a Smalltalk Symbol 
>but only a single class is used to represent both canonical and 
>non-canonical strings.

I have no problem with making Stephan's suggested change (I know others may also have suggested it).  Some things will slow down, but most can be located by searching for the pattern <Symbol literal> = <expression> or <expression> = <Symbol literal>.  Most of these could be replaced by == if speed is an issue, and we would be left with very little downside. (*)

It would certainly be nice to take a line item off the Squeak FAQ.

	- Dan

(*)  We should also scan all creations of Dictionary, as someone may have used a Dictionary instead of an IdentityDictionary, knowing that Symbol = ran about as fast as the == used in IdentityDictionary.






More information about the Squeak-dev mailing list