String/Symbol equality

Pascal Bourguignon pjb at imaginet.fr
Mon Sep 28 00:33:39 UTC 1998


David Stes <stes at mundivia.es> wrote:
> Pascal Bourguignon wrote:
> >
> > A relation noted with '=' should be an equivalence relation (thus
> > should be symetric).
>
> But how does it relate to classes ? I rather would expect = to be mostly
> symmetric for instances of a given class but not necessarily if you mix
> instances of different classes.


This imply that the implementor must ensure that its implementations of  
equivalence relations are actually symetric (and transitive and reflexive).

You cannot merely say that instances are of different classes, because  
everything is an object, that is, if two instances do not belong to the exact  
same sub-class, the have at least one common super-class: Object.

Last time I checked, equality was defined at the Object class level, and in  
a way that did ensure the implementation has every characteristic of  
equivalence relations.

If you don't want to break your system, then when you override this exact  
operator, you must ensure that it is done with the same semantics.


The direct relations between equivalence relations and classes is given  
(quite informaly, I agree) in the comment of #= in Object:

= anObject
	"Answer whether the receiver and the argument represent
	 the same object. [...]"

"x is the same object than y" is obviouly an equivalence relation (that's  
why it's been named #=, by the way).


Therefore if you override it in a subclass in such a way that it is no more  
an equivalence relation (rendering it asymetric, for example), then you can  
only expect chaos from your image.

__Pascal Bourguignon__





More information about the Squeak-dev mailing list