Expression Pattern Language (eXPL)

Axiom Variables

Axiom variables are a class of eXPL artifacts for initializing, populating and accessing dynamic lists. They expand the possibilites for both query inputs and outputs, as the following examples will show.

Dynamic Axioms

A dynamic list can be declared with no initial content and populated by appending dynamic axioms using the concatenation += operator. An example of this is in Birds of tutorial7, which works with bird classification data to generate a list of birds of the order "waterfowl". This is the declaration of dynamic list named "waterfowl" which is exported and initially empty:

export list<axiom> waterfowl {};

This is the dynamic axiom also named "waterfowl":

axiom waterfowl { bird , voice, feet = order.feet }

The waterfowl axiom is constructed with three terms. The "bird" and "voice" terms are set by unification with the "species" axion collection, while the "feet" term is set from the "order" axiom collection. The solution displayed on the console is:

bird=whistling swan, voice=muffled musical whistle, feet=webbed
bird=trumpeter swan, voice=loud trumpeting, feet=webbed
bird=snow goose, voice=honks, feet=webbed
bird=pintail, voice=short whistle, feet=webbed

A dynamic axiom term can be defined as one of several things:

  • Identifier - for untyped variable
  • Type + identifier - for typed variable
  • Identifier + list operator(s) - for list variable
  • Literal - for anonymous literal term

A variable can optionally be assigned to an expression to initialize it.

Dynamic List Initialization

The dynamic list declaration can specify how the list is to be populated in a one-time initialization to occur on the first time the list is evaluated. The specification consists of an optional axiom name, followed by a sequence of one or more dynamic axioms, to which a list of parameters can be optionally appended. Application Gaming in tutorial7 demonstrates a dynamic list input into a query to play one turn of a fruity poker machine. The play is framed as a 3 x 4 matrix built from a dynamic list. Unpredictability is provided by generating random numbers as dynamic list parameters. This is the list declaration:

list<axiom> spin
{ c1=3^r1, c2=2^r1, c3=0^r1, c4=1^r1 }
{ c1=0^r2, c2=1^r2, c3=2^r2, c4=3^r2 }
{ c1=2^r3, c2=1^r3, c3=3^r3, c4=0^r3 }
(
integer r1 = system.random(4),
integer r2 = system.random(4),
integer r3 = system.random(4)
);

The declaration has three dynamic axioms which are named "spin" by default. The term names use "c" - short for "column". Note that the appended list parameters are the same as dynamic axiom terms as regards what values are allowed

When you run the Gaming application, you will see unpredictable fruit combinations displayed in the console. It may come as a disappointment there is no jackpot.

Assignment and Concatenation

Apart from deferencing dynamic lists, the only operations permitted are assignment and concatenation.

Assignment

A dynamic list can be assigned to a dynamic axiom collection. This causes the previous content to be discarded before loading the new context.

Concatenation

A dynamic list can grow by concatenating any variable containing either an axiom list or term list. The caveats for working with axiom collections applies - you can only concatenate like with like.

Dynamic List Example

Application DynamicMegaCities of tutorial7 revisits the topic of grouping, this time using one dynamic list for each group so the task is completed in a single pass of the input data. This is much more efficient than one pass per group as happened in the original grouping solution (GroupedMegaCities of tutorial5).

Practical List Programming

Lists often feature in the design of algorithms, for example, sorting. It is therefore now a good opportunity to introduce the calculator, which channels the imperative paradigm.