Philosophical questions about collections

Lex Spoon lex at cc.gatech.edu
Mon Jul 9 16:40:26 UTC 2001


"Richard A. O'Keefe" <ok at atlas.otago.ac.nz> wrote:
> 	> Here's a case that seems similar to me: should 5 = 5.0 be false because
> 	> the numbers are of different classes?
> 	
> 	Good example!  Overall, "same as" seem  to be a vague concept, and we'll
> 	just have to pick for each kind of element what it means.  For numbers,
> 	allowing floats to equal integers is fine.
> 	
> It's by no means that simple, and I suggest that trying to provide
> a general definition of equality for Collections may be misguided.
> (In effect, I'm praising Smalltalk for what it leaves OUT.)
> 
> Take the numbers.  5 and 5.0 are NOT equivalent in Smalltalk.
>     [x := 5   * (2 raisedTo: 53). x + 1 = x] value is false
>     [x := 5.0 * (2 raisedTo: 53). x + x = x] value is true 
> If they behave differently, it doesn't make a lot of sense to regard them
> as equal.


You argue this here, and then argue differently below for collections.

In my view, it's simply very risky to make equality comparisons
involving floats.  However, it would be even worse to have two numbers
that are none of #<, #>, or #=.  People using floats should simply know
what they are up against.  (floats should never be used casually,
because of problems just like this one!)

In general, we both agree that #= needs to be defined case by case, and
that it's often arbitrary what exactly #= means.


> 
> Does anyone else find it odd that
>     (1 to: n) includes: x
> can be true for a value x such that
>     (1 to: n) anySatisfy: [:e|e = x]
> is false?
> 
> Let's confine ourselves to messages that do not alter the receiver,
> because I've always understood = to be about value of current state,
> so that (1 to: 4) and #(1 2 3 4) are not distinguished by #at:put:.

That's fine with me, though I prefer these to be #~=.

A fine default definition for #= in Collection, IMHO, would be:

	= aCollection
		self class == aCollection class and: [
			self asArray = aCollection asArray ].

Using #species instead of #class would be okay, as well -- I can't
decide which is better.


Granted, as with comparing floats, it is dangerous in many cases to use
this method.  Is it really useful to ask whether, say, two Heap's are #=
?


> 
> One thing is clear:  the definitions of #= in Interval and
> SequenceableCollection are, taken together, broken in 3.0[3552].
>     (1 to: 4) = #(1 2 3 4)
> is neither true nor false, it is a runtime error.  Apparently
> Interval>> = thinks that
>     self "an Interval" species == argument species
> implies that the argument is also an interval, which it doesn't.

Bleck, that's ugly.  The system should at least be consistent, which is
what I think the OP was going after with this thread.


Lex




More information about the Squeak-dev mailing list