Next section: Equality Comparisons5. Comparisons
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 = and <. By extending the behavior of = and <, programs can extend the behavior of the other methods.For the protocol to work, all methods on = and < must preserve the following properties:
- Identity:
- If (a == b), then (a = b).
- Transitivity:
- If (a < b) and (b < c), then (a < c).
- If (a = b) and (b = c), then (a = c).
- Trichotomy:
- Exactly one of: (a < b), (a = b), (b < a) always holds
- (on the assumption that these two operations are defined for the objects in question).[ 12,13]