Case is a form of conditional in which a ”key” value is compared against a set of values in order to choose a corresponding set of forms to evaluate. The ”key” value must be an integer. This is a restricted cond, and therefore can be compiled into more efficient code. The compiler expends some effort to examine special cases (for example compact vs. non-compact sets of cases and short vs. long sets of cases).
|nil||the default case|
|(i1 i2 ... in)||where each ik is an integer|
|((range low high))||where low and high are integers and low is less|
|than or equal to high|
The following example illustrates the use of case
After I is evaluated, it is compared against the members of each key-part in turn. If the key is eq to any member of the key-part then each of the forms in that selectq-clause are evaluated. The value of the last form of the list is the value of the selectq. If a selectq-clause with key-part t or otherwise is reached, its forms are evaluated without further testing. A t or otherwise clause should be the last clause. If no clause is satisfied then nil is returned.