functions

sfunction_definition:=
csyntax | sadjectives pointer_type sdeclname sfun_arg* sopt_traint_eq scompound
cbind | sadjectives sfun_kind sdeclname fun_return_type sopt_cstring sopt_prec srequires_clause ;
functions | sadjectives sfun_kind sdeclname sfun_arg* fun_return_type => sexpr ;
functions | sadjectives sfun_kind sdeclname sfun_arg* fun_return_type = scompound
functions | sadjectives sfun_kind sdeclname fun_return_type = smatching+ ;
sfun_kind:=
functions | cfunCFunction
functions | genGenerator
functions | funFunction

The function kinds have the following semantics:

fun
An ordinary Felix function. Must not have side-effects. The representation is indeterminate, and may be a C++ class with an apply() method, an ordinary C function, or nothing if all applications are inlined away.
cfun
Enforces creation of a C style function.
gen
Create a generator. A generator is a function with side-effects, which includes any kind of object creation (such as a C++ string), or function which impacts external state such as malloc() or random().

Generator applications are always lifted out of expressions and the result of the application assigned to a temporary variable, which replaces the application in the original expression. This ensures a generator application is evaluated exactly one if the enclosing expression is evaluated. This feature is similar to C sequence points.

sfun_arg:=
functions | ( sparameter_comma_list when sexpr )
functions | ( sparameter_comma_list )
functions | NAME
fun_return_type:=
functions | : stypeexpr expect sexpr
functions | : stypeexpr
functions | expect sexpr
functions | epsilon(typ_none none)

A function return specification consists of an optional type and an optional expected postcondition. The special identifier result can be used in the postcondition to denote the returned value. If the postcondition is omitted it is quivalent to true, otherwise the postcondition is check after every application.

If the return type is not specified, the compiler will try to calculate it from the function definition. Occasionally this will fail for recursive functions due to the interaction with overloading and recursive types. Reusable library functions should always provide an explicit return type annotation.