equal? ( obj1 obj2 -- ? )
Factor handbook » The language » Objects » Equality

Prev:= ( obj1 obj2 -- ? )
Next:identity-tuple


Vocabulary
kernel

Inputs
obj1an object
obj2an object


Outputs
?a boolean


Generic word contract
Tests if two objects are equal.

User code should call = instead; that word first tests the case where the objects are eq?, and so by extension, methods defined on equal? assume they are never called on eq? objects.

Method definitions should ensure that this is an equality relation, modulo the assumption that the two objects are not eq?. That is, for any three non-eq? objects a, b and c, we must have:
a = b implies b = a
a = b and b = c implies a = c

If a class defines a custom equality comparison test, it should also define a compatible method for the hashcode* generic word.

Examples
An example demonstrating why this word should only be used to define methods on, and never called directly:
USING: kernel prettyprint ; 5 5 equal? .
f

Using = gives the expected behavior:
USING: kernel prettyprint ; 5 5 = .
t


Definition

GENERIC: equal? ( obj1 obj2 -- ? )


Methods