Chapter 4

Program Control

Conditional Execution

There are a number of statements and function macros that can be used to conditionally execute code. These are described in detail in Chapter 14, The Built-In Macros and Special Definitions.

Table 4-2 Conditional Execution

Macro / Operator

Description

Page

if

Executes an implicit body if the value of a test is true or an alternate if the test is false.

395

unless

Executes an implicit body unless the value of a test is true.

396

case

Executes a number of tests until one is true, and then executes an implicit body associated with the true test.

397

select

Compares a target object to a series of potential matches, and executes an implicit body associated with the first match found.

398

|

Returns the value of the first of two operands that is true. This is a logical or operation.

412

&

If the value of a first operand is true, executes a second operand and returns its values. This is a logical and operation.

412

True and False

For the purposes of conditional execution, there is a single object that counts as false, and all other objects count as true.

The false object is the constant #f. There is a canonical true object, #t, which can be used for clarity of code. #t and #f are instances of the class <boolean>.

Because all values besides #f count as true, the term true or false is not equivalent to #t or #f.

The operator ~ is used for logical negation. If its operand is true, it returns #f. If its operand is #f, it returns #t.