Having an equality implies:
- maximum sharing by avoiding creation of duplicate objects;
- successive unpickling produce identical objects ...
- therefore allowing for a simple saving of caches;
- possibility to implement utilities such as diff.
EqualProc:
TYPE =
PROC [object1, object2: Object]
RETURNS [equal:
BOOL ←
FALSE];
Invariant: Equal[object1, object2] => Class[object1]=Class[object2] and Hash[object1]=Hash[object2].
EqualProcs can assume that object1 and object2 are of the same class.
Equal: EqualProc;
If objects are REF-equal it is easy.
If classes are different or if hashes are different, objects must be different.
Then, if there is an EqualProc, it is applied; otherwise FALSE is returned.