Next: comparisons branch, Previous: comparisons default, Up: comparisons [Index]
The syntactic extensions defined in this section are the primary utilities for defining new compare procedures as conveniently as possible.
The arguments, if any, must be expressions; they are evaluated from left to right until a non–zero value is found (which then is the value) or until there are no more arguments to evaluate (in which case the value is ‘0’). If no arguments are supplied, the return value is ‘0’.
Each clause, with the possible exception of the last, is of the form:
(?type? ?c1 ...)
where ?type? is an expression evaluating to a predicate procedure, and ?ci are expressions evaluating to an exact integer in {-1, 0, 1}. The last clause may be an “else clause”, which has the form:
(else ?c1 ...)
select-compare
is a conditional for defining hierarchical
extensions and refinements of compare procedures. It compares the
values of expr1 and expr2 by trying the type tests in order,
and applies an implict refine-compare
on the consequences upon a
match.
In more detail, evaluation proceeds as follows: First expr1 and expr2 are evaluated in unspecified order, resulting in values x1 and x2, respectively. Then the clauses are evaluated one by one, from left to right.
For clause:
(?type? ?c1 ...)
first ?type? is evaluated resulting in a predicate procedure
type? and then the expressions (type? x1)
and
(type? x2)
are evaluated and interpreted as
booleans:
(refine-compare ?c1 ...)
An else clause is treated as if both tests where true. If there are no clauses left, the result is ‘0’.
select-compare
evaluates expr1 and expr2 exactly
once, even in the absence of any clauses. Moreover, each ?type?
is evaluated at most once and the resulting procedure type? is
called at most twice.
Each ?clause, with the possible exception of the last, is of the form:
((?t1 ?t2) ?c1 ...)
where ?t1 and ?t2 are expressions evaluating to booleans, and ?ci are expressions evaluating to an exact integer in {-1, 0, 1}.
The last clause may be an “else clause”, which has the form:
(else ?c1 ...)
cond-compare
is another conditional for defining hierarchical
extensions and refinements of compare procedures.
Evaluation proceeds as follows: The clauses are evaluated one by one, from left to right. For clause:
((?t1 ?t2) ?c1 ...)
first ?t1 and ?t2 are evaluated and the results are interpreted as boolean values:
(refine-compare ?c1 ...)
An else clause is treated as if both booleans where true. If there are no clauses left (or there are no clauses to begin with), the result is ‘0’.
cond-compare
evaluates each expression at most once.
Next: comparisons branch, Previous: comparisons default, Up: comparisons [Index]