Template-Axiom-Query (TAQ)

Flow

A template creates a query solution in a sequential and orderly manner, like an assembly line. A structure called a "flow" is a template that allows it's terms to divert the flow of execution away from the body to perform some function and return. This gives rise to the expression "sideways execution" as it contrasts with the normal top-down sequencing of a template. The term "flow" conveys the concept of continuous progression from start to finish. All execution advances one term at a time.

Loop

As an example of sideways execution, imagine how the cursor introduced in personalities2.taq can take advantage of a "loop" template that executes in a loop until a criterion causes it to short circuit. The compiler can check that the loop contains at least one criterion to avoid an infinite loop. The cursor code can change from

string personality = traits++ + " " + traits++ + " " + traits

to

string personality = "",
loop
(
? fact traits,
personality += traits++ + " "
)

The immediate advantage of loop over the original code is that, if by chance the "traits" list is empty, this will be dealt with gracefully. Better still, the number of items in the list no longer has to be the same in each case.

For loop to be a success it must have access to all the variables declared above in the host template and participate in unification just like it's host. The loop integrates with the host template so closely that a minimal format has been decided on - that tis o simply enclose the template terms in braces. Hence the template transformed into a flow looks like this

flow name_match
{ cursor<string> traits }
(
name ? name == search_name,
age,
starsign,
string personality = "",
{
? fact traits,
personality += traits++ + " "
}
)

Note that the loop in the above flow has no meaningful value to pass to it's solution. As a term, a loop is always private.

Branch

A branch is the same as a loop except it does not iterate and exists only to respond to a condition evaluated by a criterion or function. convert_mi2.taq demonstrates branch attached to a criterion.

? unit == imperial
{ surface_area *= 2.59 }

The branch converts a surface area measured in in square miles to square kilometers. The condition for taking the branch is the incoming surface area "unit" is "imperial". Any term, like this one, which attaches a branch to a criterion is automatically marked as private as there is no meaningful value that can be applied.

Compact Loop and Compact Branch

Both loop and branch have a compact format for when the body contains only a single term. In this case the criterion has a distinctive format

?? (expression)

This represents a test of the expression's fact status and the criterion is only satisfied if the fact status is true. Here is the above example branch written as a compact branch

?? (unit == imperial) surface_area *= 2.59

A compact loop has identical format to a compact loop except it is enclosed in braces to signify it iterates while waiting for the criteria to fail. Here is the previous loop example written as a compact loop

{ ?? (traits) personality += traits++ + " " }