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


2.38.12 Comparison procedure constructors

Function: make-comparison< lt-pred
Function: make-comparison> gt-pred
Function: make-comparison<= le-pred
Function: make-comparison>= ge-pred
Function: make-comparison=/< eq-pred lt-pred
Function: make-comparison=/> eq-pred gt-pred

These procedures return a comparison procedure, given a less–than predicate, a greater–than predicate, a less–than–or–equal–to predicate, a greater–than–or–equal–to predicate, or the combination of an equality predicate and either a less–than or a greater–than predicate.

They are the same as the corresponding SRFI-67 compare-by procedures. Note that they do not accept comparand arguments.

Usage examples:

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

(let ((compare (make-comparison< fx<?)))
  (compare 1 1)        ⇒ 0
  (compare 1 2)        ⇒ -1
  (compare 2 1))       ⇒ +1

(let ((compare (make-comparison> fx>?)))
  (compare 1 1)        ⇒ 0
  (compare 1 2)        ⇒ -1
  (compare 2 1))       ⇒ +1

(let ((compare (make-comparison<= fx<=?)))
  (compare 1 1)        ⇒ 0
  (compare 1 2)        ⇒ -1
  (compare 2 1))       ⇒ +1

(let ((compare (make-comparison>= fx>=?)))
  (compare 1 1)        ⇒ 0
  (compare 1 2)        ⇒ -1
  (compare 2 1))       ⇒ +1

(let ((compare (make-comparison=/< fx=? fx<?)))
  (compare 1 1)        ⇒ 0
  (compare 1 2)        ⇒ -1
  (compare 2 1))       ⇒ +1

(let ((compare (make-comparison=/> fx=? fx>?)))
  (compare 1 1)        ⇒ 0
  (compare 1 2)        ⇒ -1
  (compare 2 1))       ⇒ +1