Identity vs equality (was Re: [Newbies] Assignment)
stephane ducasse
stephane.ducasse at free.fr
Mon Aug 13 12:35:33 UTC 2007
I agree that the symmetry in the solution is a must else we would
have really strange behavior (like the ones you mentioned).
I was wondering what is the advantage to have strings and symbols
been equals. I still do not understand deeply the pros and the
cons of each approach. This is true that we could consider that a
symbol is a special string (unique) but I wonder what are the in
terface incompatibility. My question is if today I would have to
design a library would I make the difference or not. And I'm puzzled.
Stef
On 12 août 07, at 21:21, Andreas Raab wrote:
> stephane ducasse wrote:
>> But I'm confused do you imply that the order in which the elements
>> were added had an impact on the set?
>
> Yes.
I agree indeed it is quite important.
>
>> in VisualWorks
>
> Well, but in VisualWorks also:
>
> String>>= aString
> "Answer whether the argument is a string, and is not a symbol,
> and the receiver's size is the same as aString's size, and each of
> the receiver's
> elements equal the corresponding element of aString"
>
> | size |
> aString isString ifFalse: [^false].
> aString isSymbol ifTrue: [^false].
> (size := self size) = aString size ifFalse: [^false].
> 1 to: size do:[:index | (self at: index) = (aString at: index)
> ifFalse: [^false]].
> ^true
>
> So in other words, in VisualWorks Strings and Symbols always
> compare false which is perfectly symmetric.
>
> Cheers,
> - Andreas
>
>
More information about the Squeak-dev
mailing list
|