Recursion is available for assignments. For example, suppose that you
wish to generate a random walk with noise:
. This could be generated via the
following assignment:
Whenever we reference this assignment, [B/D] notes the recursive aspect
and deduces, by back tracking through the recursion, what is actually
intended. This requires some termination criterion. By default, any
quantity with a varying index which becomes zero, becomes zero itself.
(If a varying index becomes negative, this results in an error.)
Under this rule, [B/D] would deduce that , as
is taken to be zero. Otherwise, termination criteria
can be set explicitly by defining an element. This works as follows.
An assignment is defined as a linear combination of elements, components, and other assignments. Therefore, and ignoring self-referential assignments which cause an error, it is possible to trace through the definition part until it is solely in terms of elements and components.
When an assignment is referenced, [B/D] tries to determine the linear combination of elements and components intended in the definition part of the assignment. If the definition part of the assignment contains other assignments, these too are tracked through to determine the intended linear combination of elements and components. Eventually all the assignments in the definition part will either vanish because they are replaced by their own definitions, or as the recursion nears zero, they become zero by default, or because of terminating criteria established beforehand. Consider, for example, the following fragment of code (#phi is an example of a function, described more fully in chapter 7).
BD>assign : Z.t=(#phi) Z.(t-1)+E.t
When the assignment is referenced, [B/D] will take into
account the recursion involving
and
. Moreover, as
the elements X.1 and Z.2 exist, these will take priority over the
implied assignments of the same name, and the recursion will terminate
at these points. For example, suppose that we now wished to construct
. The assignments and termination criteria imply