Template-Axiom-Query (TAQ)

Receiver

An execution branch attached to a function is called a "receiver" as it has the special behavior that the terms of any returned axiom can be directly accessed in the branch. This has the effect that, just as a function can be passed parameters when called, it can return parameters on completion. This feature works well with the select operation, as the returned parameters are conveniently named in the declaration header. If a function returns a type other than an axiom, then the return value is accessed using a variable with the same name as the function.

Format

The receiver format consists of the following four components:

flow identifier( parameters ) { flow-body }

The identifier will be a one or two part name depending on where the function being called is located. For a select operation, the first parameter provides the key and cannot be omitted. Additional call parameters in a select operation can set default values of one or more select parameters named in the declaration header..

The following examples demonstrate the receiver format for a variety of function return types starting with axiom.

Select Axiom

stamp-duty2.taq changes the original by attaching a receiver to the "sale_bracket" select function. The receiver performs a calculation using variables with names matching "threshold", "base" and "percent" in the sale_bracket declaration header. These variables are set from the corresponding terms of the selection axiom. Here is the "stamp_duty_payable" flow

flow stamp_duty_payable
{ currency.USD amount }
(
. duty = currency.USD 20.00,
. flow sale_bracket(amount) {
duty = base + (amount - threshold) *
(percent / 100)
},
term id,
amount.format(),
bracket = sale_bracket.index() + 1,
string payable = duty.format()
)

Note one particular behavior of a select function is that the receiver evaluation is skipped if there is no match. Therefore the original branch on success strategy is preserved for when the sale amount is above $5,000.

Axiom List

The following examples should look familiar as they are taken from previous topics and modified to apply the receiver format instead of the original variable assignment format.

receive-student-scores.taq has a function which returns an axiom list containing subject scores in alphabetical format. Attached to this function is a receiver to create a report. The receiver has a cursor named "convert_grades", the same as the function, so it unifies with the returned axiom list

flow school.convert_grades(english, maths, history) {
cursor<axiom> convert_grades,
{
...
}}

receive-student-scores2.taq replaces the function call with a query call to a template. The list of subjects in this case is contained in a "subjects" term belonging to the returned template solution axiom. Therefore the receiver for this application is identical to the first except the name of the cursor this time is "subjects" as returned axiom terms can be directly accessed by the receiver.

Axiom Term List

receive-service-items.taq demonstrates applying an axiom term list, as defined by a "service_amount" archetype declaration, to a receiver. The archetype has 2 terms named "service" and "amount". This creates a potential ambiguity as the library function has the name "amount". Fortunately, the 2 amounts have different types to allow them to be differentiated. The amount term unifies with receiver currency variable

currency.USD amount

but the amount function returned value does not because of a type mismatch