next up previous contents
Next: Calling queries in answer Up: User-defined Answer Formats Previous: Simple expressions in patterns

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:

tabular1506

Iteration 2:

tabular1511

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. If one wants a comma inside an an expresssion (e.g. expr), then one has to escape it ` tex2html_wrap_inline3164 ,'. The same holds for the other special characters like `(', `)' etc.



ConceptBase Team