6.8 Object Equality and Hashing (original) (raw)

6.8 Object Equality and Hashing🔗

By default, objects that are instances of different classes or that are instances of a non-transparent class are equal? only if they are eq?. Like transparent structures, two objects that are instances of the same transparent class (i.e., every superclass of the class has #f as its inspector) are equal? when their field values are equal?.

To customize the way that a class instance is compared to other instances by equal?, implement the equal<%>interface.

The equal<%> interface includes three methods, which are analogous to the functions provided for a structure type withprop:equal+hash:

The equal<%> interface is unusual in that declaring the implementation of the interface is different from inheriting the interface. Two objects can be equal only if they are instances of classes whose most specific ancestor to explicitly implementequal<%> is the same ancestor.

Example: