next up previous contents
Next: Special characters Up: User-defined Answer Formats Previous: Pre-defined variables

Iterations over expressions

In case of expressions with multiple values, the user may want to generate a complex text that uses one value after the other as a parameter. The `Foreach' construct allows to solve this requirement.

{Foreach( (expr1,expr2,...), (x1,x2,...), expr )}

The expression expr1 is evaluated yielding each a list of solutions s11,s12,... The same is applied to expr2 yielding a list s21,s22,... Then, the variables x1,x2,... are matched against the first entries of all lists, i.e. x1=s11,x2=s21,... This binding is then applied to the expression expr which should contain occurences of {x1}, {x2}, ... This replacement is continued with the second entries in all lists yielding bindings x1=s12,x2=s22,... This is continued until all elements of all lists are iterated. If some lists are smaller than others, the missing entries are replaced by NULL.

During each iteration, the new bindings induce substitution rules for the binding

Iteration 1:

tabular1826

Iteration 2:

tabular1831

Note that the third argument expr may contain other subexpressions, even a nested `Foreach'. An example for iterations is given in iterations.sml in the directory $CB_HOME/examples/AnswerFormat/.

The Foreach-construct contains three arguments separated by commas. These two commas are used by ConceptBase to parse the arguments of the Foreach-construct and similar answer formatting expressions. They are not printed to the answer stream.



ConceptBase Team