Like the arithmetic operations, the test operations can take more than
two arguments. For example,
(< 1 2 3) is legal Scheme
notation for ``1 < 2 and 2 < 3.'' The
or operators also take any number of arguments. The
not operation always takes one argument. The
not operators work on Boolean values only.
Exercise 3.3.1 The
= operator works on numbers,
only, so trying to test a Boolean function using the pattern
(= (in-interval-1? 0) false)
false, you can create a test claim using
(not (in-interval-1? 0))
true, it needs no wrapper.
cond expression must contain a sequence of
condition lines, where each line has exactly two parts:
(cond [condition1 answer1] [condition2 answer2] ...)
condexpression is typed into DrScheme, DrScheme highlights the incorrect part of the expression as a syntax error. If an individual condition line is highlighted, then only that line is incorrect. If multiple lines are highlighted, then the parentheses are not balanced in an individual line (so DrScheme thinks that multiple lines are a single line).
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
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 syntax for forming a
expression, the following is a legal expression:
(cond [1 2])
false. It is neither, so DrScheme highlights the
1and prints an error message. This is a run-time error.
The following is another legal expression according to the syntax
(cond [true 5] [1 2])
1would be an illegal condition value if the second condition is ever tested, DrScheme never tests it since the first condition is always
cond expression is evaluated, at least one of the
conditions must be
true. If no condition is
then DrScheme prints the run-time error ``no matching cond case.''
For example, the following expression generates the ``no matching
cond clause'' error, since there is only one condition and it is
(cond [false 0])
condexpression with an
elseclause never generates the ``no matching case'' error because the
elseclause always matches.
Automatic Parenthesis Correction
When you type an close parenthesis
) where an open bracket
[ needs to be closed, DrScheme automtically changes
] to close the bracket. For example, typing
(define (positive? n) (cond [(> n 0) true
], instead of
]may be automatically converted to
). Automatic parenthesis correction is handy, but if it bothers you, turn it off via the Edit|Preferences menu item.
No DrScheme notes for this section.