Next: srfi compare-procedures spec const, Previous: srfi compare-procedures spec pair, Up: srfi compare-procedures spec [Index]
It is convenient to have a compare procedure readily available for comparing most built in types.
Compare its arguments by type using the ordering:
null < pair < boolean < char <
< string < symbol < number < vector < other
Two objects of the same type type are compared as
type-compare would, if there is such a procedure. The type
null consists of the empty list (). The effect of
comparing two other objects or of comparing cyclic structures (made from
lists or vectors) is unspecified. (Implementations are encouraged to
add comparisons for other built in types, e.g. records, regexps, etc.)
RATIONALE
default-comparerefinespair-compareby splitting neither-null-nor-pair.
NOTE
default-comparecould be defined as follows (mind the order of the cases!):(define (default-compare x y) (select-compare x y (null? 0) (pair? (default-compare (car x) (car y)) (default-compare (cdr x) (cdr y))) (boolean? (boolean-compare x y)) (char? (char-compare x y)) (string? (string-compare x y)) (symbol? (symbol-compare x y)) (number? (number-compare x y)) (vector? (vector-compare default-compare x y)) (else (error "unrecognized types" x y))))