► |  | How to Design Programs Languages

1 | Beginning Student
2 | Beginning Student with List Abbreviations
3 | Intermediate Student
4 | Intermediate Student with Lambda
5 | Advanced Student
| Index

▼ | 1 | Beginning Student

1.1 | define
1.2 | define-struct
1.3 | Function Calls
1.4 | Primitive Calls
1.5 | cond
1.6 | if
1.7 | and
1.8 | or
1.9 | Test Cases
1.10 | empty
1.11 | Identifiers
1.12 | Symbols
1.13 | true and false
1.14 | require
1.15 | Primitive Operations

On this page:

cond
else

Version: 4.1.4
top← prev up next →

#### 1.5`` cond

(cond [expr expr] ... [expr expr])

A cond form contains one or more “lines” that are surrounded by parentheses or square brackets. Each line contains two exprs: a question expr and an answer expr.

The lines are considered in order. To evaluate a line, first evaluate the question expr. If the result is true, then the result of the whole cond expression is the result of evaluating the answer expr of the same line. If the result of evaluating the question expr is false, the line is discarded and evaluation proceeds with the next line.

If the result of a question expr is neither true nor false, it is an error. If none of the question exprs evaluates to true, it is also an error.

(cond [expr expr] ... [else expr])

This form of cond is similar to the prior one, except that the final else clause is always taken if no prior line’s test expression evaluates to true. In other words, else acts like true, so there is no possibility to “fall off the end” of the cond form.

else

The else keyword can be used only with cond.

top← prev up next →