iterate
MetaScript functions iterate
syntax
- iterate(iteration_names, template, init_expr_item)
definition
iterate instantiates template once per entry of the string Attribute iteration_names and chains the iterations: the first subitem of each instantiation (by convention currValue) receives as expression the previous iteration’s nextValue (the first iteration receives the expression held by the string Parameter init_expr_item). The result container also gets an item lastValue with the nextValue of the final iteration as its expression. That item is untyped, so a typed Parameter or Attribute cannot take lastValue as its calculation rule: the engine reports ItemType DataItem is incompatible with the result of the calculation which is of type TreeItem (checked with GeoDMS 20.19). Refer to the nextValue of the last iteration by name instead, res/it2/nextValue in the example below.
example
unit<uint32> iters: nrofrows = 3 { attribute<string> name := 'it' + string(id(.)); }
parameter<string> init := 'uint32(0)';
template step
{
parameter<uint32> currValue;
parameter<uint32> nextValue := currValue + uint32(1);
}
container res := iterate(iters/name, step, init);
res/it2/nextValue results in 3. A worked example with attributes as the iterated value, the Newton-Raphson steps of a logistic regression, is on Linear and logistic regression.