► |  | 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

▼ | 5 | Advanced Student

5.1 | define
5.2 | define-struct
5.3 | lambda
5.4 | Function Calls
5.5 | begin
5.6 | begin0
5.7 | set!
5.8 | delay
5.9 | shared
5.10 | let
5.11 | recur
5.12 | case
5.13 | when and unless
5.14 | Primitive Operations
5.15 | Unchanged Forms

On this page:

case

Version: 4.1.4
top← prev up next →

#### 5.12`` case

(case expr [(choice ...) expr] ... [(choice ...) expr])

A case form contains one or more “lines” that are surrounded by parentheses or square brackets. Each line contains a sequence of choices – numbers and names for symbols – and an answer expr. The initial expr is evaluated, and the resulting value is compared to the choices in each line, where the lines are considered in order. The first line that contains a matching choice provides an answer expr whose value is the result of the whole case expression. If none of the lines contains a matching choice, it is an error.

(case expr [(choice ...) expr] ... [else expr])

This form of case is similar to the prior one, except that the final else clause is always taken if no prior line contains a choice matching the value of the initial expr. In other words, so there is no possibility to “fall off the end” of the case form.

top← prev up next →