chickadee » srfi-128 » make-comparator

make-comparator type-test equality ordering hashprocedure

Returns a comparator which bundles the type-test, equality, ordering, and hash procedures provided. However, if ordering or hash is #f, a procedure is provided that signals an error on application. The predicates comparator-ordered? and/or comparator-hashable?, respectively, will return #f in these cases.

Here are calls on make-comparator that will return useful comparators for standard Scheme types:

(make-comparator boolean? boolean=? (lambda (x y) (and (not x) y)) boolean-hash)

will return a comparator for booleans, expressing the ordering #f < #t and the standard hash function for booleans.

(make-comparator real? = < (lambda (x) (exact (abs x))))

will return a comparator expressing the natural ordering of real numbers and a plausible (but not optimal) hash function.

(make-comparator string? string=? string<? string-hash)

will return a comparator expressing the implementation's ordering of strings and the standard hash function.

(make-comparator string? string-ci=? string-ci<? string-ci-hash)

will return a comparator expressing the implementation's case-insensitive ordering of strings and the standard case-insensitive hash function.