Expression Pattern Language (eXPL)

eXPL Axiom Variables

Axiom variables hold axiom lists and like other variables can be set by assignment in an expression or by unification. In addition, axiom variables can grow by concatenation, accepting both axiom lists and axiom term lists. Concatenation is allowed only if the axiom list of the axiom variable is empty or contains the same number of terms as the list participating on the other side. Note the concatenation operator is +=, the same as for strings.

Format

An Axiom variable declaration has format:

axiom name = axiom-initializer.

An axiom-initializer can be:

  • axiom-list-expression, for example, a variable containing an axiom list generated in a previous operation
  • axiom-term-list-expression, in which case the axiom variable adapts to access terms instead of axioms
  • axiom-list-literal, which is described in more detail below. An empty list is indicated by empty {} braces

Note that the axiom-initializer is required whenever a variable is explicitly typed as an "axiom". An untyped variable, when assigned an axiom list as a value, will adapt to behave the same as an Axiom variable.

Two important features particular to Axiom variables:

  1. When an Axiom variable references a list containing a single axiom, then an array index can used to reference axiom terms by name. See "expand" axiom in Regex Groups Example for an example
  2. The axiom list value is automatically included in the query result. The list is referenced in code using the name of the Axiom variable.

Axiom List Literal

Axiom List Literals declare one or more axioms to assign to an axiom variable. Each axiom must have the same number of terms, but terms need not have literal values. The terms can be variables which are set in a unification+evaluation step. Each axiom is enclosed in {} braces and there is no separator between axioms. Axiom terms are comma-separated.

Here is an example of an Axiom variable initialized with a Axiom List Literal containing 3 axioms. The variable is used to pass the marks in 3 school subjects, with a character grading system replacing a numeric score:

axiom marks_list =
  { "English", mark[(english)] }
  { "Math",    mark[(math)] }
  { "History", mark[(history)] }

Each axiom has two terms, the first being a string literal for the name of the subject and the second a list variable indexed by an integer variable. The second term obviously can only be set in a unification+evaluation step. Terms containing just a literal value will be anonymous, while any other type of term will have a name extracted according to how it is defined. In the above case, the mark term name is the list and index names joined with an underscore eg. "mark_english".

This how the marks_list contents looks when displayed:

English, mark_english = b
Math, mark_math = a-
History, mark_history = e+

Unamed Axiom List Literals

An Axiom List Literal is not named when used with an Axiom variable in an assignment or concatenation operation. For example, here an unnamed high city axiom is concatenated to a high cities list:

axiom high_cities = {};
high_cities += axiom { name , altitude }

The axiom created on the right hand side adopts the name of the list on the left hand side and therefore does not end up anonymous.

High Cities with Axiom Variable

The High Cities is revisited this time using an Axiom variable to collect and return the results of the query. Note that the "high_cities" Axiom variable of the example is declared before the template that uses it. Axiom variables are likely to be preferred over Axiom lists unless the number of results are expected to be too high to hold in memory.

axiom high_cities = {};

template high_city(
  altitude ? altitude > 5000,
  high_cities += axiom { name , altitude }
);
query high_cities (city : high_city);

tutorial7 HighCitiesAxioms code example runs this query. The console output when the query is run displays the contents of high_cities list:

high_cities(name = flagstaff, altitude = 6970)
high_cities(name = addis ababa, altitude = 8000)
high_cities(name = denver, altitude = 5280)
high_cities(name = leadville, altitude = 10200)
An axiom variable can refer to a list that is declared after the axiom variable is declared