<=?
Syntax: (<=? comparator a b c ...) Library: (srfi 128) Description: Returns #t if each argument is less than or equal to the next. Example: (<=? (make-default-comparator) 1 1 2) => #t
SRFI-128 — Comparators: bundled type-test, equality, ordering, and hash procedures
SRFI-128 provides comparators: bundles of a type test, an equality predicate, an ordering predicate, and a hash function. They give a single value that fully describes how to compare and hash a kind of data — used by hash tables (SRFI-125) and ordered collections.
(import (srfi 128))
(define c (make-comparator number? = < #f)) ;; type=, equal=, order=, hash=
(comparator? c) ;; => #t
(=? c 3 3) ;; => #t
(<? c 1 2) ;; => #t
make-default-comparator returns a general-purpose comparator, and there are predefined comparators and combinators for building comparators over compound data.
35 bindings
Syntax: (<=? comparator a b c ...) Library: (srfi 128) Description: Returns #t if each argument is less than or equal to the next. Example: (<=? (make-default-comparator) 1 1 2) => #t
Syntax: (<? comparator a b c ...) Library: (srfi 128) Description: Returns #t if each argument is less than the next according to the comparator. Example: (<? (make-default-comparator) 1 2 3) => #t (<? (make-default-comparator) 1 1) => #f
Syntax: (=? comparator a b c ...) Library: (srfi 128) Description: Returns #t if all arguments are equal according to the comparator. Example: (=? (make-default-comparator) 1 1 1) => #t (=? (make-default-comparator) 1 2) => #f
Syntax: (>=? comparator a b c ...) Library: (srfi 128) Description: Returns #t if each argument is greater than or equal to the next. Example: (>=? (make-default-comparator) 3 3 1) => #t
Syntax: (>? comparator a b c ...) Library: (srfi 128) Description: Returns #t if each argument is greater than the next according to the comparator. Example: (>? (make-default-comparator) 3 2 1) => #t
Syntax: (boolean-hash obj) Library: (srfi 128) Description: Returns a hash value for a boolean. Example: (integer? (boolean-hash #t)) => #t (= (boolean-hash #t) (boolean-hash #t)) => #t
Syntax: (char-ci-hash obj) Library: (srfi 128) Description: Returns a case-insensitive hash value for a character. Example: (= (char-ci-hash #\A) (char-ci-hash #\a)) => #t
Syntax: (char-hash obj) Library: (srfi 128) Description: Returns a hash value for a character. Example: (integer? (char-hash #\a)) => #t (= (char-hash #\a) (char-hash #\a)) => #t
Syntax: (comparator-check-type comparator obj) Library: (srfi 128) Description: Like comparator-test-type but raises an error if obj fails. Example: (comparator-check-type (make-default-comparator) 42) => #t
Syntax: (comparator-register-default! comparator)
Library: (srfi 128)
Description: Registers a comparator to be used by the default comparator for types
that satisfy the registered comparator's type test.
Example:
(comparator-register-default!
(make-comparator string? string=? string<? string-hash))
Syntax: (comparator-test-type comparator obj) Library: (srfi 128) Description: Returns #t if obj satisfies the type test of the comparator. Example: (comparator-test-type (make-default-comparator) 42) => #t
Syntax: (default-hash obj) Library: (srfi 128) Description: Returns a hash value for any object using the default hashing strategy. Example: (integer? (default-hash 42)) => #t (integer? (default-hash "hello")) => #t
Syntax: (hash-bound) Library: (srfi 128) Description: Returns the upper exclusive bound for hash values. Implementation-defined. Example: (> (hash-bound) 0) => #t
Syntax: (hash-salt) Library: (srfi 128) Description: Returns a salt value for hash functions. Returns 0 in this implementation. Example: (integer? (hash-salt)) => #t
Syntax: (make-comparator type-test equality ordering hash) Library: (srfi 128) Description: Creates a comparator from four procedures. type-test is a predicate that returns #t for valid arguments. equality is an equivalence predicate. ordering is an ordering predicate (or #f if not provided). hash is a hash function (or #f if not provided). If equality is #t, equal? is used. Example: (define c (make-comparator string? string=? string<? string-hash)) (comparator? c) => #t (comparator-ordered? c) => #t
Syntax: (make-default-comparator) Library: (srfi 128) Description: Returns a comparator that handles booleans, characters, strings, symbols, numbers, null, pairs, and vectors, with ordering and hashing support. Example: (define c (make-default-comparator)) (=? c 1 1) => #t (<? c 1 2) => #t (<? c "a" "b") => #t
Syntax: (make-eq-comparator) Library: (srfi 128) Description: Returns a comparator that uses eq? for equality. Example: (define c (make-eq-comparator)) (comparator? c) => #t
Syntax: (make-equal-comparator) Library: (srfi 128) Description: Returns a comparator that uses equal? for equality and default-hash for hashing. Example: (define c (make-equal-comparator)) (comparator? c) => #t (comparator-hashable? c) => #t
Syntax: (make-eqv-comparator) Library: (srfi 128) Description: Returns a comparator that uses eqv? for equality. Example: (define c (make-eqv-comparator)) (comparator? c) => #t
Syntax: (make-list-comparator element-comparator type-test empty? head tail) Library: (srfi 128) Description: Returns a comparator for list-like sequences using the given element comparator and sequence access procedures. Example: (define c (make-list-comparator (make-default-comparator) list? null? car cdr)) (=? c '(1 2 3) '(1 2 3)) => #t
Syntax: (make-pair-comparator car-comparator cdr-comparator) Library: (srfi 128) Description: Returns a comparator for pairs that compares car and cdr using the given comparators. Example: (define c (make-pair-comparator (make-default-comparator) (make-default-comparator))) (=? c '(1 . 2) '(1 . 2)) => #t
Syntax: (make-vector-comparator element-comparator type-test length ref) Library: (srfi 128) Description: Returns a comparator for vector-like sequences using the given element comparator and vector access procedures. Example: (define c (make-vector-comparator (make-default-comparator) vector? vector-length vector-ref)) (=? c #(1 2 3) #(1 2 3)) => #t
Syntax: (number-hash obj) Library: (srfi 128) Description: Returns a hash value for a number. Example: (integer? (number-hash 42)) => #t (= (number-hash 3.14) (number-hash 3.14)) => #t
Syntax: (string-ci-hash obj) Library: (srfi 128) Description: Returns a case-insensitive hash value for a string. Example: (= (string-ci-hash "Hello") (string-ci-hash "hello")) => #t
Syntax: (string-hash obj) Library: (srfi 128) Description: Returns a hash value for a string. Example: (integer? (string-hash "hello")) => #t (= (string-hash "abc") (string-hash "abc")) => #t
Syntax: (symbol-hash obj) Library: (srfi 128) Description: Returns a hash value for a symbol. Example: (integer? (symbol-hash 'foo)) => #t (= (symbol-hash 'bar) (symbol-hash 'bar)) => #t