Next: , Previous: , Up: comparisons   [Index]


1.17.4 Comparing atoms

This section describes comparison procedures for most of the atomic types of R6RS: booleans, characters, strings, symbols, and numbers. As a general naming convention, a procedure named:

type-compare-order

compares two objects of the type type with respect to a total order for which order is a mnemonic hint (e.g. ‘-ci’ for case–insensitive). Of course, ‘-order’ may be absent if there is just one order or the order is obvious. It is an error if a comparison procedure accepting objects of a certain type is called with one or two arguments not of that type.

Function: boolean-compare bool1 bool2

Compare two booleans, ordered by #f < #t. A non–false value is not interpreted as a “true value,” but rather an error will be signalled.

Function: char-compare char1 char2
Function: char-compare-ci char1 char2

Compare characters as char<=? and char-ci<=? respectively. The suffix -ci means “case insensitive.”

Function: string-compare string1 string2
Function: string-compare-ci string1 string2

Compare strings as string<= and string-ci<=?. The suffix -ci means “case insensitive.”

Function: symbol-compare symbol1 symbol2

Compares symbols as string<= on the names returned by symbol->string.

Function: integer-compare x y
Function: rational-compare x y
Function: real-compare x y
Function: complex-compare x y
Function: number-compare x y

Compare two numbers using the R6RS functions = and <. It is an error if an argument is not of the type specified by the name of the procedure.

Complex numbers are ordered based on their magnitude:

(real-compare (magnitude x) (magnitude y))

If at least one among x and y is a complex number: number-compare defaults to complex-compare, else it defaults to real-compare.

If one or both the arguments is ‘+nan.0’:

integer-compare
rational-compare

Raise an error because ‘+nan.0’ is neither integer nor rational.

real-compare
complex-compare
number-compare

Return ‘+nan.0’.


Next: , Previous: , Up: comparisons   [Index]