[BUG] equivalence between strings and symbols
R. A. Harmon
harmonra at webname.com
Wed Apr 12 13:38:44 UTC 2000
At 09:57 PM 4/11/00, Lex Spoon wrote:
>"R. A. Harmon" <harmonra at webname.com> wrote:
>
>> I am trying to implement an ANSI conforming #=. As I understand it, #abc
>> (an instance of class Symbol) = 'abc' (an instance of class String) would be
>> non-conforming implementation as their classes are different.
>>
>
>Apparently it's ambiguous. Allen Wirfs-Brock gave a pretty good
>argument earlier today.
As I read his explanation the ANSI Standard is not ambiguous, it just allows
various implementation. The SequenceableCollection >> #= specification:
Refinement: <sequenceReadableCollection>
Unless specifically refined, the receiver and operand are equivalent if all
of the following are true:
1. The receiver and operand are instances of the same class.
2. They answer the same value for the #size message.
3. For all indices of the receiver, the element in the receiver at a
given index is equivalent to the element in operand at the
same index.
means same class when it says same class.
>So we can choose whichever way we like, and just remember that if we
>want to write portable Smalltalk code, we can't rely on it working one
>way or the other. :(
--- Allen Wirfs-Brock:
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.
---
Badly simplified, we can choose to implement String and Symbol as a single
class, say StringSymbol, used to represent both and only then would:
#abc (an instance of class StringSymbol)
= 'abc' (an instance of class StringSymbol) -> true
As I read it there are other possible variations in implementation.
--
Richard A. Harmon "The only good zombie is a dead zombie"
harmonra at webname.com E. G. McCarthy
Spencer, Iowa
More information about the Squeak-dev
mailing list
|