Philosophical questions about collections

Lex Spoon lex at cc.gatech.edu
Tue Jul 3 03:05:23 UTC 2001


Diego Gomez Deck <DiegoGomezDeck at ConsultAr.com> wrote:
> I can 'fix/complete' the Collection tree, but I'd like to know the 
> community thinking....
> 
> My idea is that #= answer with true when the two collection have the same 
> specie, the same contents, the same order, the same keys and the same 
> occurrences.
> 

Sounds good, although some of it will depend on the collection type. 
Two Sets can have the same elements but different #do: orderings because
of the order the elements were added, but it seems like they should
still be #=.  

Also, it really seems like the two collections should have the same
*class* -- (1 to: 4) isn't really the same as #(1 2 3 4).


> We need some extras messages to handle the other ways to compare collection:
> 
> #sameContent:   ignores the specie, ignores the order, ignores the keys and 
> ignores the occurrences.
> #exactContent:   ignores the specie, ignores the order, ignores the keys 
> but care of the occurrences.
> #sameKeys:       the two collection has the same Set of keys, don't care 
> about the specie.
> 

I agree that comparing collections has several interpreterations, but
I'm not sure what the exact list should be.  Note that each of these can
already be done with only a little more work:

sameContent -> x asSet = y asSet
exactContent -> x asBag = y asBag
samKeys -> x keys asSet = y keys asSet

And I'm not so sure the list of variations is going to end any time
soon.  I'm not sure they won't, to be fair.  :)  But how about #= versus
#== on the elements, for example?

Until there's reason to believe that the list of types of comparisons
has been sorted out, I'd lean towards letting people type out what they
mean explicitly.

All MHO.  Others have probably thought about this more than either of us
-- collections are a pretty neat part of Smalltalk!


Lex





More information about the Squeak-dev mailing list