Dylan provides an identity function, as well as a group of equality and magnitude comparison functions that can be extended for user classes. The methods =, /=, <, >, <=, and >= are defined in terms of binary= and binary<. By extending the behavior of binary= and binary<, programs can extend the behavior of the six methods.
For the protocol to work, all methods on binary= and binary< must preserve the following properties:
In addition, classes which provide their own definition of binary= should provide a definition for =hash, if instances of the class will be used as keys in = hash tables.
See Also: Dylan Design Notes: Variadic Operators (Change)
Equality Comparisons
Objects are considered identical if they are computationally equivalent. That is, there is no way for any possible Dylan program to distinguish them. FN24
= is not guaranteed to return (for example, when called on circular structures or unbounded structures).
= is a method, so you cant add other methods to it. To extend the protocol, define methods on binary=.
/= is a method, so you cant add other methods to it. To extend the protocol, define methods on binary=.
id?> object1 object2 #rest objects ==> boolean [Method]
id? returns true if object1, object2, and all the objects are all identical. Otherwise, it returns false.
= object1 object2 #rest objects ==> boolean [Method]
= returns true if every object is binary= to every other object. Otherwise, = returns false.
/= object1 object2 ==> boolean [Method]
/= calls binary= on object1 and object2. Returns true if binary= returns false FN25.
binary=[next citation] object1 object2 ==> boolean [Generic Function]binary= is called by = and other comparison predicates. Programs should not normally call this function directly.
The predefined methods on binary= behave as follows:
This implies that the collections are the same size. For sequences, this means that elements at the same position are =.
=hash=hash object ==> integer [Generic Function]returns a hash-code for object. If you define any methods for binary= and wish to use objects affected by that definition as keys in = tables, then you must define corresponding methods for =hash.
The rule is that if two objects are =, then they must generate the same hash code when passed to =hash.
The value returned by =hash must be a integer.
See Also: Dylan Design Notes: Variadic Operators (Change)
Magnitude Comparisons
< is a method, so you cannot add other methods to it. To extend the protocol, define methods on binary<.
> is a method, so you cannot add other methods to it. To extend the protocol, define methods on binary<.
<= is a method, so you cannot add other methods to it. To extend the protocol, define methods on binary<.
>= is a method, so you cannot add other methods to it. To extend the protocol, define methods on binary<.
The predefined methods on binary< behave as follows:
< object1 object2 #rest objects ==> boolean [Method]
< compares the objects two at a time with binary<. If each object is less than the one to its right, < returns true. Otherwise < returns false.
> object1 object2 #rest objects ==> boolean [Method]
> compares the objects two at a time with binary< (with appropriate argument reordering). If each object is greater than the one to its right, > returns true. Otherwise, > returns false.
<= object1 object2 #rest objects ==> boolean [Method]
<= compares the objects two at a time with binary< (with appropriate argument reordering). If each object is less than or equal to the one to its right, <= returns true. Otherwise, <= returns false.
>=>= object1 object2 #rest objects ==> boolean [Method]
>= compares the objects two at a time with binary<. If each object is greater than or equal to the one to its right, >= returns true. Otherwise, >= returns false.
binary<[next citation] object1 object2 ==> boolean [Generic Function]
Called by <, >, and other functions. Programs should not call this function directly.