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


1.17.9 Branching

The facilities described in this section provide a mechanism for using a compare procedure (passed as a parameter) in the different situations arising in applications.

Syntax: if3 ?c ?less ?equal ?greater

?c, ?less, ?equal, and ?greater are expressions.

if3 is the 3–way conditional for comparisons. First ?c is evaluated, resulting in value c. The value c must be an exact integer in {-1, 0, 1}, otherwise an error is signalled.

c = -1

The value of the if3 expression is obtained by evaluating ?less.

c = 0

?equal is evaluated.

c = 1

?greater is evaluated.

Syntax: if=? ?c ?consequent
Syntax: if=? ?c ?consequent ?alternate
Syntax: if<? ?c ?consequent
Syntax: if<? ?c ?consequent ?alternate
Syntax: if>? ?c ?consequent
Syntax: if>? ?c ?consequent ?alternate
Syntax: if<=? ?c ?consequent
Syntax: if<=? ?c ?consequent ?alternate
Syntax: if>=? ?c ?consequent
Syntax: if>=? ?c ?consequent ?alternate
Syntax: if-not=? ?c ?consequent
Syntax: if-not=? ?c ?consequent ?alternate

?c, ?consequent, and ?alternate are expressions. If ?alternate is not provided, (if #f #f) is used.

These six macros are 2–way conditionals for comparisons. First ?c is evaluated, resulting in value c. The value c must be an exact integer in {-1, 0, 1}, otherwise an error is signalled. Then, depending on the value of c and the name of the macro, either ?consequence or ?alternate is evaluated, and the resulting value is the value of the conditional expression.

The branch is chosen according to the following table:

?consequent?alternate
if=?c = 0c in {-1, 1}
if<?c = -1c in {0, 1}
if>?c = 1c in {-1, 0}
if<=?c in {-1, 0}c = 1
if>=?c in {0, 1}c = -1
if-not=?c in {-1, 1}c = 0

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