String/Symbol equality
Maloney
johnm at wdi.disney.com
Thu Sep 24 18:41:35 UTC 1998
This issue comes up periodically. The difference results from
the fact a Symbol wants equalit to mean "identical objects"
whereas a String wants it to mean "collection-like objects with
the same contents".
To my way of thinking, the receiving object really *should* get
to choose its own meaning for the "=" message, just as the
it can decide what "+" or any other message means.
Thus, although the asymmetry of "=" is surprising when you
first run into it, I think it ends of making perfect sense
when you think about it from the message passing perspective.
-- John
>#size = 'size' ==> false
>'size' = #size ==> true
>
>Shouldn't they both return true?
>
>Symbol>>#= anObject
> ^self == anObject
>
>Perhaps the previous method should be eliminated, and an identity shortcut
>should be added to the following.
>
>SequenceableCollection>>#= otherCollection
> "Answer whether the species of the receiver is the same as
> otherCollection's species, and the receiver's size is the same as
> otherCollection's size, and each of the receiver's elements equal the
> corresponding element of otherCollection."
> | size |
> self == anObject ifTrue: [^true]. "<- IDENTITY SHORTCUT"
> (size _ self size) = otherCollection size ifFalse: [^false].
> self species == otherCollection species ifFalse: [^false].
> 1 to: size do:
> [:index |
> (self at: index) = (otherCollection at: index) ifFalse:
>[^false]].
> ^true
>
>--Maurice
>
>---------------------------------------------------------------------------
> Maurice Rabb 773.281.6003 Stono Technologies, LLC Chicago, USA
More information about the Squeak-dev
mailing list
|