spec

Software for Diffraction

2.4.4.4. - Macro Functions



Macro functions are a type of macro that can return values and can be used as an operand in expressions. The macro definition can include function arguments, which then become available to the body of the macro function. For example,
def factorial(n) '{
        if (n <= 1)
                return(1);
        return(n * factorial(n-1))
}'
The syntax of macro functions requires the macro name followed by a set of parenthesis which can contain a comma-separated list of argument names. The arguments names become local variables within the macro definition. The definition must be a statement block, that is, the statements must be enclosed in curly brackets.