The case expression is used to select an expression to be evaluated from a set of labeled expressions based on a test value compared against the labels.
Only the first expression whose label matches the test expression is evaluated. All labels must be comparable to the test expression. Labeled expressions can be block-expressions, so you can use the case expression as a case statement, choosing between blocks of code to execute.
where <expr> is the test expression and <cases> is a sequence of labeled expressions:
new_obj = case copy_type.state of
2: copy $foo
3: instance $foo
default: reference $foo
A special label, default, can be optionally used to tag the expression that will be evaluated if no other labels match the test expression. If the default label is not used, and no label matches the test expression, the case expression returns a value of undefined.
The test expression is optional. If it is not supplied, the labels are expected to be Boolean values or expressions, and the first label evaluated as true determines the chosen case. In this variant, it is common to use expressions as labels, so be sure to parenthesize them.
(a > b): print "a is big"
(b < c): print "b is little"
(c <= d*3): ...