A cond expression must contain a sequence of
condition lines, where each line has exactly two parts:
(cond [condition1 answer1] [condition2 answer2] ...)
Just like an expression in a definition, no extra parentheses can be added around the condition or answer expressions in a cond-line. Parentheses cannot be placed around else.
Beyond the Shape Rules
The rules concerning the shape of a cond expression do not
specify the kind of condition expressions that are allowed.
In fact, a condition expression must have a Boolean value. For
example, according to the shape rules for forming a cond
expression, the following is a legal expression:
(cond [1 2])
The following is another legal expression according to the shape
rules:
(cond [#t 5] [1 2])
The difference between errors reported because a cond expression has the wrong shape (syntax errors) and error reported because the expression returns the wrong kind of result (run-time errors) is explained in 7 Syntax and Semantics in the book.
When a cond expression is evaluated, at least one of the
conditions must be #t. If no condition is #t, then
DrScheme prints the error ``no matching cond case.'' (This is another
kind of run-time error.) For example, the following expression
generates the ``no matching cond clause'' error, since there is only
one condition and it is #f:
(cond [#f 0])
Automatic Parenthesis Correction
When you type an close parenthesis ) where an open bracket
[ needs to be closed, DrScheme automtically changes
) to ] to close the bracket. For example, typing
) after
(define (positive? n) (cond [(> n 0) #t