Here we implement a 'case'-statement (a bit like case in Pascal or switch in C or Java).

The idea is that the case has a list of clauses, (tag,function)-pairs. The result of the case is a function that depends on a 'selection-key'. Providing this function with a value, it checks the value against all the tags and it returns the appropriate function. So, the result of the case is a function that still has to be called. Notice that, for efficiency, the case internally builds a table ranging from 1 to the value of the highest tag. So, do not use this case with e.g. the tags 3, 4 and 10000 because this will allocate a table with 10000 functions in it. Luckily, the MC-eval only uses the case with small amounts of (consecutive!!) tags.

Here is an example:

mySelector : case( 1 => sin,
                   2 => cos,
                   else => arctan)

...

get some number 'n'

...
fun:myselector(n)
...
fun(1.0)          // This 'fun' will be sin, cos or arctan