About Dynamic Functions
It is often useful to treat an entire branch in a tree as though it were a single function that lets you supply input arguments. This can be done using Dynamic Functions.
Assume you want to calculate how much Profit increases if Sales go up by 1000.
If Profit were a function of Sales, you could simply add a node such as:
However, Profit is a constant rather than a function, so this definition does not work. However, you can still perform this calculation if you refer to Profit as a Dynamic Function as follows:
When DScript evaluates the formula:
it realizes Profit is not a function, so it assumes you want to treat the entire branch beginning at Profit as a Dynamic Function. To do this, DScript first evaluates the expression inside the parentheses; then it runs the Profit branch; and finally, it removes all definitions created while evaluating the parentheses expression.
The expression inside the parentheses can perform any operation including completely redefining key parts of the branch. For example, the following expression not only sets Sales to a new value, it also redefines the node Variable:
In using a Dynamic Function, you are asking DScript to evaluate a branch with a list of temporary changes. This is a good way to embed scenario testing in your applications.