8.11. Function definition

Synopsis: data_type function_name ( [ typed_parameters ] ) function_body

A function definition creates a new function in the current namespace named function_name with a parameter list typed_parameters that has function_body attached for evaluation. The function_body must return a value of type data_type and the arguments passed upon function call must match the type definitions in typed_parameters.

Example 8.19. Function definition

{
    void nothing()
    {
	y2milestone("doing nothing, returning nothing");
    }

    integer half( integer value )
    {
	return value / 2;
    }

    map <string, integer> get_some_map () {
	return listmap (string key, ["a", "b", "c"], {
	    return $[key : random(999)];
	});
    }

    // This renders: ...nothing: nil  -  half: 21...
    y2milestone("nothing: %1  -  half: %2", nothing(), half(42) );
    
    // This renders something like: new half-random map: $["a":839, "b":393, "c":782]
    y2milestone("new half-random map: %1", get_some_map());
}