Next: srfi compare-procedures spec pair, Previous: srfi compare-procedures spec atom, Up: srfi compare-procedures spec [Index]
In this section compare procedures are defined for Scheme lists and vectors—and for objects that can be accessed like lists or like vectors.
An object x can be accessed like a vector if there are procedures
size and ref such that (size x)
is a non–negative integer
N indicating the number of elements, and (ref x
i)
is the i-th element of x for i \in
{0, ..., N - 1}. The default vector access procedures are
vector-length
and vector-ref
.
An object x can be accessed like a (proper) list if there are
procedures empty?
, head
, and tail
such that:
(empty? x)
Is a boolean indicating that there are no elements in x.
(head x)
Is the first element of x.
(tail x)
Is an object representing the residual elements of x.
The default list access procedures are null?
, car
, and
cdr
.
Independent of the way the elements are accessed, the natural ordering of vectors and lists differs:
Compare two sequences x and y, using compare for
comparing elements. The result is an exact integer in {-1, 0,
+1}
. If compare is not supplied, default-compare
is
used.
The procedure named access-compare-as-order
accesses
the objects like access and compares them with respect to the
order given by order. The names type-compare
are
abbreviations for type-compare-as-type
.
Examples:
(list-compare '(2) '(1 2)) ⇒ 1 (list-compare-as-vector '(2) '(1 2)) ⇒ -1 (vector-compare '#(2) '#(1 2)) ⇒ -1 (vector-compare-as-list '#(2) '#(1 2)) ⇒ 1
Next: srfi compare-procedures spec pair, Previous: srfi compare-procedures spec atom, Up: srfi compare-procedures spec [Index]