Skip to content

function

Tim Vaughan edited this page Mar 16, 2015 · 6 revisions

The <function> element allows users to define named functions that can be used inside of rateMultiplier and predicate expressions. It has the following structure:

    <function spec='Function' id="STRING" params="STRING STRING ... STRING">
        <!-- Expression String -->
    </function>

The id attribute is used to specify a unique name for the function.

The params attribute contains a space-delimited list of the parameter names.

The value of the element contains an "expression string", the syntax of which is described on the MASTER expression syntax page.

Once such a function is defined, it can be referred by rateMultiplier and predicate expressions. For instance, the following defines a function named "myFunc" that returns the length of the hypotenuse of a right-angled triangle with sides "x" and "y":

    <function spec='Function' id="myFunc" params="x y">
        sqrt(x^2 + y^2)
    </function>

Inside of a rateMultiplier or predicate expression, this function can be invoked using the notation "myFunc(E1,E2)" where E1 and E2 are constants, variables or any other valid expressions.

Note that functions can be invoked within function definitions, either recursively or non-recursively.