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


2.38.8.5 Vector comparators

Function: make-vector-comparator element-comparator

Build and return a comparator object behaving like vector-comparator but using element-comparator rather than default-comparator.

#!vicare
(import (vicare) (srfi :114))

(define-constant C
  (make-vector-comparator exact-integer-comparator))

;; type test
(comparator-test-type C '#())           ⇒ #t
(comparator-test-type C '#(1 2))        ⇒ #t
(comparator-test-type C '#(1 2.0))      ⇒ #f
(comparator-test-type C "ciao")         ⇒ #f
(comparator-test-type C '#(1+2i)        ⇒ #f

;; type check
(comparator-check-type C '#(1 2))       ⇒ #t
(try
    (comparator-check-type C (void))
  (catch E
    ((&comparator-type-error)
     #t)
    (else E)))
⇒ #t

;; comparison
(comparator-compare C '#(1 2) '#(1 2))  ⇒ 0
(comparator-compare C '#(1 2) '#(1 3))  ⇒ -1
(comparator-compare C '#(1 3) '#(1 2))  ⇒ +1

(comparator-compare C '#()    '#())     ⇒ 0
(comparator-compare C '#()    '#(1 2))  ⇒ -1
(comparator-compare C '#(1 2) '#())     ⇒ +1

;; hash
(non-negative-exact-integer?
  (comparator-hash C '#())))    ⇒ #t
(non-negative-exact-integer?
  (comparator-hash C '#(1 2)))  ⇒ #t
Function: make-vectorwise-comparator type-test element-comparator length ref

Return a comparator which compares two objects that satisfy type-test as if they were vectors, using the length procedure to determine the length of the object, and the ref procedure to access a particular element.