Expression Pattern Language (eXPL)

Axiom Lists

An axiom is a fundamental eXPL artifact so dealing with collections of axioms is an important issue. Such collections need to be accessed as an ordered sequence of axioms and each axiom, in turn, requires access to inidividual terms. Having established a syntax and operations for basic types, axioms follow suit, but additional requirements are:

  • Terms, unlike basic types, potentially have a name
  • Selection of a term in an axiom list requires a 2-dimensional reference
  • Templates produce axioms as solutions which may need to be exported or accessed by other templates
  • Axioms in collections need to share a common footprint

The starting point will not be the axiom list, but instead it's associate, the term list which is the second dimension of an axiom list. The term list is an axiom wrapper which provides access to axiom terms using a convenient syntax.

Term Lists

A term list is similar to a basic list, but the list implementation is an axiom, so a list variable adopts the type of the term it selects, rather than the type being pre-determined. The -> operator is also provided to select an axiom term by name. The format to declare an axiom term list is:

list<term> name ( axiom )

An example is given in the Colors application of tutorial7. This is the axiom:

axiom color_map
(   aqua  ,  black ,  blue    )
{ | "red" | "white"|"yellow"| };

Each term of the "color_map" axiom maps a color to it's inverse eg. black to white. Note the use of pipe character | to create columns, which is an alternative format. This is the example term list, named "inverse_color", attached to template "shade":

template shade
+ list<term> inverse_color(color_map);
(
inverse_of = name,
inverse_color[name]
);

This is the console output:

shade(inverse_of=aqua, name=red)
shade(inverse_of=black, name=white)
shade(inverse_of=blue, name=yellow)

Two things to note about the list variable inverse_color[name]:

  1. A term list variable derives it's identity from the index - hence term name seen in output
  2. A term list variable accepts either an integer or string value for the index
Solution term list

A query or a template can be designated as a solution exporter using the term list syntax eg. query<term> types(literals:variables); is a query which exports the solution as a term list with name "types". If the query produces more than one solution, then the list will contain the last solution. When a template is declared as a term list, then the list is available to all templates that follow.

Term List Behaviour

A term list provides both read and write access to the referenced axiom and can append terms as well. Note that axiom modification is restricted once it is inserted into a collection. All axioms in a collection share the same archetype which determines:

  1. The number of terms
  2. The term name at each position
  3. The term type at each position

For a term list, this equates to changing a term value as the only modification allowed to an axiom in a collection. Changing a term value is demonstrated in the BlackIsWhite application of tutorial7. This declares a single axiom called "patch" which has a color name and the 3 RGB color values:

axiom patch (name, red, green, blue)
{"blank", 0, 0, 0};

The application transitions the patch through a sequence of colors, which are inverted from the colors input into the query. Here is the console output:

before=blank, name=red, red=255, green=0, blue=0
before=red, name=white, red=255, green=255, blue=255
before=white, name=yellow, red=255, green=255, blue=0

Notable in the program is the use of the -> operator to access axiom terms eg. before = color2->name. Also note the use of the dot operator before a template term to suppress exporting the term. Without the dot operator, the output contains additional, redundant terms. You can experiment by removing the the dots to see what happens.

2nd Axiom List Dimension

An axiom list can be resolved down to a particular term by using one of two available operators for the 2nd dimension, which are array [] for selection of term by index and dot . for selection by term name. So if we have a "city_elevations" axiom list where the second term of each axiom is named "altitude", then for an axiom at index "i", this term can be referenced as city_elevations[i][1] or city_elevations[i].altitude. Obviously the latter variant is preferred because it is self-evident what term is being referred to.