The pattern as well as head and tail of an answer format may contain the call to a query (possibly the same for which the answer format was defined for). This allows to generate arbitrarily complex answers.
{ASKquery(Q[subst1,subst2,...],FRAME)}
The argument Q is the name of a query. The arguments subst1,subst2 are parameter substitutions (see section 2.3). The argument `FRAME' is fixed and present for historical reasons here. The effect is that the above query is evaluated and the expression is replaced by the complete answer.
In terms of the substitution, the following rule is applied:
{ASKquery(Q[subst1,subst2,...],FRAME)}
X
where X is the result of the query call Q[subst1,subst2,...] after derivation of the arguments subst1, subst2 etc. This sequencing is important since
an ASKquery call can contain terms that are subject to substitution, e.g.
{ASKquery(MyQuery[{this.cat1}/param1,{this.{x1}}/{x2}],FRAME)}. ConceptBase will always start to evaluate left tp right and the
innermost terms before evaluating the terms that contain inner terms. Hence, the derivation sequence is
where we assume the following example substitution rules
This guarantees that the query call is `ground', i.e. does not contains terms which are subject to substitution.
The ASKquery construct allows to introduce recursive calls during the derivation of a query since there can (and should) be an answer format for Q which may contain expressions ASKquery itself. In principle, this allows infinite looping. However, the answer format evaluator prevents such loops by halting the expansion when a recursive call with same parameters has occured. The answer then contains an `' character at the position where the loop was detected.
A simple example for use of ASKquery is given in recursive-answers.sml. The example uses a view instead of a query class in order to include also answers into the solution which not have a filler for the requested attribute, i.e. hasChild is inherited_attribute, not retrieved_attribute.
It is common practice to combine the ASKquery construct with `Foreach' in order to display an iteration of objects in the same way. The user should define an answer format for the iterated query Q as well.
Do not mix the use of ASKquery with the view definitions in ConceptBase. The nesting depth of a view is determined by the view definition. The nesting depth of an answer generated by expansion of ASKquery is only limited by the complexity of the database. For example, one can set up an ancestor database and display all descendants of a person and recursivley their descendants in a single answer string for that person.