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:
{ | "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":
+ list<term> inverse_color(color_map);
(
inverse_color[name]
This is the console output:
shade(inverse_of=black, name=white)
shade(inverse_of=blue, name=yellow)
Two things to note about the list variable inverse_color[name]:
- A term list variable derives it's identity from the index - hence term name seen in output
- 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.
Axiom Lists
There are 4 types of axiom lists which reflect how the axiom collections they refer to are implemented. We have already encountered 3 of these types because it is impossible to program in eXPL without using axiom lists:
- Literal - Refers to axiom collection declared in program
- Solution - Refers to solution evaluated by the program
- External - Refers to external implementation, which may be both readable and writeable
- Dynamic - Refers to axiom collection created by executing the program
Literal Axiom Lists
This type of list has the simplest format:
list name(axiom)
Here the list keyword is used without a type modifier. The axiom names a literal axiom collection, which has format:
axiom name( [term-names ] ) { literals } ...
The term names can be omitted, meaning the terms are anonymous, and when term names are specified, the number of terms should match the number of term names.
The name of an axiom collection can be used as a query parameter. Application HighCitiesListed in tutorial7 declares an anonymous-term axiom collection which is the input into the "high_cities" query.
Solution Lists
As the name implies, this type of list exports a solution generated by a template. There are 3 formats for specifying a solution list:
- query<axiom> name (...)
- template<axiom> name (...)
- list name(template)
Format 1 query generates a solution list with the same name as the query. Application HighCitiesAxioms in tutorial7 demonstrates this type of query.
Format 2 template generates a solution list with the same name as the template.
Format 3 declares a solution list for a template with the specified name. The main difference from format 2 is in the freedom to choose the name of the list. Application HighCitiesListed in tutorial7 demonstrates solution list attached to a template which names itself as the list target. Note that a 2-part name, "high_city.city_list" is needed to get this list from the result. Also note that a solution list does not need the export modifier.
