The case Expression

The case expression is a convenient way to test a value against several discrete possibilities. The format is:

(case key
(values_1 expressions_1 )
(values_n expressions_n ) )

Each values_i is a list of values. The values_i are not evaluated, so symbols that are used as values should not be quoted. else may be used as a final key value that is always satisfied.

; Select kind of wine
(define (wine dish)
  (case dish
    ((beef)         'red)
    ((chicken fish) 'white)
    (else           'rose)) )

> (wine 'fish) white

> (wine 'hot-dog) rose

Contents    Page-10    Prev    Next    Page+10    Index