Next: , Previous: , Up: srfi comparators   [Index]


2.38.3 Definitions

A comparator is an object of a disjoint type. It is a bundle of procedures that are useful for comparing two objects either for equality or for ordering. There are four procedures in the bundle:

Type test predicate

It returns #t if its argument has the correct type to be passed as an argument to the other three procedures, and #f otherwise.

Equality predicate

It returns #t if the two objects are the same in the sense of the comparator, and #f otherwise. It is the programmer’s responsibility to ensure that it is reflexive, symmetric, transitive, and can handle any arguments that satisfy the type test predicate.

Comparison procedure

It returns -1, 0, or +1 if the first object precedes the second, is equal to the second, or follows the second, respectively, in a total order defined by the comparator. It is the programmer’s responsibility to ensure that it is reflexive, weakly antisymmetric, transitive, can handle any arguments that satisfy the type test predicate, and returns 0 if and only if the equality predicate returns #t. Comparison procedures are compatible with the compare procedures of SRFI-67; see SRFI-67 for the rationale for adopting this return convention.

Hash function

It takes one argument, and returns an exact non–negative integer. It is the programmer’s responsibility to ensure that it can handle any argument that satisfies the type test predicate, and that it returns the same value on two objects if the equality predicate says they are the same (but not necessarily the converse).

It is also the programmer’s responsibility to ensure that all four procedures provide the same result whenever they are applied to the same object(s) (in the sense of eqv?), unless the object(s) have been mutated since the last invocation. In particular, they must not depend in any way on memory addresses in implementations where the garbage collector can move objects in memory.


Next: , Previous: , Up: srfi comparators   [Index]