Template-Axiom-Query (TAQ)

Basic Lists

Basic lists, as the name suggests, contain items of a basic type which will be one of string, integer, double, decimal, currency or boolean. There are also term lists and axiom lists which share the same characteristics as basic lists but have extra features that are described in the next topic.

The following aspects of Lists are to be covered:

  • Declaration
  • Export
  • Access
  • Navigation

List Declaration

A List declaration has following format:

list<type> name

This format is just a minimal list declaration with various features that can be added according to how the list is to be used. A list can be declared in any scope or template. A list declaration, except for one located in a template body, can include an assignment to an item set , The item set consists of a comma-delimited list of literal values enclosed in braces. Here is an example of assigning a set of numbers to an integer list:

list<integer> dice = { 1, 2, 3, 4, 5, 6 }
List Variable

When a list is declared in the body of a template, then it is referred to as a "list variable" and like other variables it has the potential to be set by unification and/or be passed to the solution. Unlike other variables, a list variable being empty is a valid state as it just means there are no items in the list. A list variable can have one of 2 roles - as either providing access to an external list or as a local list of the template. In the first case it is set by unification and in the latter, it is set by appending items to it.

personalities.taq shows a list variable used to reference an external list. It looks up a database containing person details including Zodiac sign and associated personality traits. The search for "John" returns:

Name: John, Age: 23, Zodiac: Gemini
Traits: gentle, affectionate, curious

The Gemini traits are stored as a string list:

list<string> gemini_traits = {
"gentle", "affectionate", "curious"
}

John's data contains a "traits" term with a list reference to above list. Other names with various Zodiac signs to try are are Alex, Sue, and Sam,

list<axiom> person
(name, sex, age, starsign, traits)
{"John", "m", 23, "Gemini", list gemini_traits}
...

The "name_match" template's 4th term is a list variable with name "traits" to match on the term with the same name in "persons" axiom list.

template name_match
(
name ? name == search_name,
age,
starsign,
list<string> traits
)
List Examples

lists.taq demonstrates basic lists for all types except currency and includes term and axiom lists to show they share characteristics of basic lists. For each type there is a list declaration and a template which contains the list items and the size of the list. This application does not run a query as it is easier, in this case, to access each template directly.

Note the use of square brackets to reference items by index and the "length" attribute to find how many items are in each list.

List Range

It is possible to declare a bound list with defined start and end index values:

list<type> name ( start,end )

The "start" value is first valid index value and "end" is the last valid index value. When a range is set, then an item can be inserted at any location within the range. Without a range set, a list can only grow by appending items to the end of it. Care must be used when a range is set as a list will contain empty locations unless/until the program fully populates it.

assign-marks.taq shows a list with range of 1 to 18 initialized in reverse order so the alphabetical items it contains are arranged in descending order.

Export

Query results so far have been formed as axiom lists. It is also possible to pass a basic list as a query solution by exporting it. This is achieved by placing the export keyword at the start of the list declaration.

Here is an example of list named "amount_list" declared with the export modifier:

export list<currencyy> amount_list

Referencing List Items

A variable that references a list item adopts the type of that item and can therefore perform all the operations allowed for that type. Array notation allows for an expression to be used to provide the index value and it is not uncommon to use an integer post-increment expression.