help!!
Tim Olson
tim at jumpnet.com
Wed Apr 15 03:01:00 UTC 1998
Dave Farber wrote:
>today's puzzle is:
>
> Dictionary new
> at: (Set with: 1) put: 'is';
> at: (Set new add: 1; yourself) ifAbsent: ['isnot']
>
>why does this little snippet *sometimes* answer 'is' and *sometimes* answers
>'isnot'?
Because the implementation of Set makes the fundamental error of
reimplementing #=, without reimplementing #hash, which remains inherited
from Object. This means that it cannot be used as a key for Sets or
Dictionaries (as you have discovered), because its #hash value is not
based upon the equality comparison, but rather upon a pseudo-random value
kept in its header field.
The other classes in the image that do this are:
TextLine
LargePositiveInteger
CharacterBlock
TextStyle
SequenceableCollection
Text
CompiledMethod
TextLineInterval
SortedCollection
Set
TextColor
TextKern
TextFontChange
TextFontReference
TextAnchor
TextEmphasis
To be fair, it is doubtful that most of these would actually be used as
Set or Dictionary keys, but one can certainly imagine uses for some of
them (LargePositiveInteger, SequenceableCollection). I guess this should
be added to the official "cleanup list" of things to fix.
-- tim
More information about the Squeak-dev
mailing list
|