sr at evolgo.de
Fri Jun 18 05:29:50 UTC 2004
Richard A. O'Keefe wrote:
> Also interestingly, one of the classes that is filtered out that way
> is Collection, which redefines #hash (to depend on state, of course)
> but does NOT redefine #= to match. This is bad news for Bag, which
> inherits #= from object but #hash from Collection, and the two DON'T
> play together correctly. This is in Squeak 3.6#5429.
In my Squeak3.7beta there is Bag>>=, and the method is from raok
6/10/2002 (it's difficult to find, since the 'comparing' protocol is at
the bottom of the list):
"Two bags are equal if
(a) they are the same 'kind' of thing.
(b) they have the same size.
(c) each element occurs the same number of times in both of them".
(aBag isKindOf: Bag) ifFalse: [^false].
self size = aBag size ifFalse: [^false].
contents associationsDo: [:assoc|
(aBag occurrencesOf: assoc key) = assoc value
> - it is inconsistent for some kinds of Collection to define #=
> "mathematically" but others not. (For example, whatever you think
> Bag and Set should do, it is hard to think of a good argument for
> having them do *different* things.)
And Set also has a definition for #=, but it is in protocol 'testing'.
> - you don't have to look very far before you find inconsistencies
> (like Bag inheriting incompatible definitions of #= and #hash)
So it's not so bad... ;-)
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