The case statement

From Church Wiki

Jump to: navigation, search

The case statements in Church (and also in Scheme) has the following syntax:

(case key-expression
   ((object-1-1 object-1-2 ...) expression-1)
   ((object-2-1 object-2-2 ...) expression-2)
   ...
   ((object-N-1 object-N-2 ...) expression-N)
   (else else-expression))

Church first evaluates the key-expression and then tries to match its values against one of the objects in one of the match lists. If the object matches, then the corresponding expression is evaluated. If the object doesn't match anywhere then the else clause is evaluated.

This is in fact syntactic sugar for a long series of if statements (meaning that a Church implementation translates the case statement to those if statements before evaluating).

Personal tools