[BUG] equivalence between strings and symbols

Stephan Rudlof sr at evolgo.de
Tue Apr 11 02:31:05 UTC 2000


Some more thoughts and suggestions...

If we use #== for comparing Symbols -> there is no problem. So we should
use it, if we know there are only symbols (btw: there are methods called
#asSymbol).

If code relies on the asymmetry of #= in respect to Symbols and Strings,
it should be refactored after ensuring the symmetry of #=.


If *speed* for #= is a problem, because it should be impossible to avoid
mixing symbols and strings (what has to be stated!), I would suggest the
following.

Semantically:

Symbol>>
= anObject
	(anObject isMemberOf: Symbol)
		ifTrue: [^ self == anObject].
	^ super = anObject

implemented faster as:

Symbol>>
= anObject
	<primitive: xxx>
	^ super = anObject

Stephan


Stephan Rudlof wrote:
> 
> Another (new?) suggestion:
> 
> What about completely *removing* Symbol>>= ?
> 
> Has anybody tried this (without changing other methods)?
> 
> Then
>         #abc = 'abc'
>         'abc' = #abc
> should both be true; and
>         #abc == 'abc'
>         'abc' == #abc
> should both be false.
> 
> This is the 'shortest' approach and equivalence rules are valid.
> 
> Any drawbacks?
> 
> Stephan
> 
> "R. A. Harmon" wrote:
> >
> > At 10:27 AM 4/10/00 -0700, John W. Sarkela wrote:
> > [snip]
> > >Given the standard I believe that either #= in SequenceableCollection
> > >should check for class equality rather than species equality
> > [snip]
> >
> > I spent a half day playing around with changing SequenceableCollection >> #=
> > to use class, and changing String >> #= to use class or removing it
> > completely (I thought this should also work, but maybe slower).
> >
> > Squeak did not like these changes.  The version menu item loses its
> > memory--only the current version is listed, and when a method was changed
> > and accepted Squeak no longer recognized selectors already defined and asked
> > for confirmation on all the selectors and classes used in the method.
> >
> > I tried tracking the problem with versions into the Scanner methods but I'm
> > a little out of my depth and its tricky given the way the system is effected
> > by the change.  The variable "token" is not always a string but there are a
> > number of places where = symbol occurs; and assignments, especially of
> > string values, are often but not always converted to symbols.
> >
> > I'll play around with it some more and see if I can discover where it is
> > breaking.
> >
> > --
> > Richard A. Harmon          "The only good zombie is a dead zombie"
> > harmonra at webname.com           E. G. McCarthy
> > Spencer, Iowa
> 
> --
> Stephan Rudlof (sr at evolgo.de)
>    "Genius doesn't work on an assembly line basis.
>     You can't simply say, 'Today I will be brilliant.'"
>     -- Kirk, "The Ultimate Computer", stardate 4731.3

-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3





More information about the Squeak-dev mailing list