Template-Axiom-Query (TAQ)

Map and Select

A map operation attempts to pair a key to an associated value, for example mapping a country code to a country. A select operation goes further by allowing an entire row of a table to be associated with a key, for example selection by country code of country, capital and surface area in one hit. As part of either operation, the key can be evaluated by an expression, opening up the ability to work with ranges of values, regular expressions and other possibilities.

Proto Select

proto-select.taqt illustrates the design pattern that both nap and select follow. The program maps a bank account number of 1, 2 or 3 into type "sav", "cre" and "chq" respectively. The "map_account" flow features a number match criterion for each account and an "accounts" axiom list to provide the text account values

flow map_account
{ integer account,
integer i,
axiom list accounts(account_type)
{ "sav" }
{ "cre" }
{ "chq" }
}
( account_type,
{
?: account == 1,
++i,
?: account == 2,
++i,
?: account == 3,
i = -1,
?: false
},
? i != -1
{ account_type = accounts[i] }
)

A selection index, "i" is the link between the account number and the account type. A final criterion ?: false provides an exit for the default case of the account number is unrecognized. Both the actual map and select formats require only the axiom list terms and criteria to be programmed while hiding the other implementation details.

Map

Here is an actual account type map:

map account {
? 1: "sav"
? 2: "cre"
? 3: "chq"
}

The map keyword is followed by key "account", which is expected to be local variable containing either 1, 2 or 3. The map format allows the subject of each criteria to be omitted if it is the key. The ==: operator can also be dropped if diong a comparison, Hence ? 1: for the first criteria instead of ? account == 1:.

Map is never used in isolation but is always placed on the right-hand side of a variable assignment. Here is an example of a template containing a map statement:

account_type =
map account
{
? 1: "sav"
? 2: "cre"
? 3: "chq"
}
Default Selection

The default case, if applicable, can be dealt with in one of 3 ways:

  1. Set the map result variable to the default value before the map statement.
  2. Have a final criterion for "everything else" such as ? true:
  3. Check the fact status of the variable holding the map result and branch accordingly

Grouping with List Map

Assigning a map to a list variable is supported and allows grouping to be performed in a single pass of the input data. The constraints are that the keyword combination list map must be used to distinguish the map from an ordinary one, and each selection must be an identifier of a previously declared list. dynamic-grouping.taq groups cities by continent using a list map pointing to 5 export dynamic axiom lists (asia, africa, europe ...), one for each continent:

mega_city = list map Continent
{
? "Asia": asia
? "Africa": africa
? "Europe": europe
? "South America": south_america
? "North America": north_america
}

The application displays cities grouped in turn by continent.