Prev Up Next

The cond form is convenient for expressing nested if-expressions, where each ``else'' branch but the last introduces a new if. Thus, the form

(if (char<? c #\c) -1
    (if (char=? c #\c) 0
        1))

can be rewritten using cond as:

(cond ((char<? c #\c) -1)
      ((char=? c #\c) 0)
      (else 1))

The cond is thus a multi-branch conditional. Each clause has a test and an associated action. The first test that succeeds triggers its associated action. The final else clause is chosen if no other test succeeded.

The cond actions are implicit begins.

Prev Up Next