Expression Pattern Language (eXPL)

eXPL Terms

Terms are sequences of items contained in axioms and templates. All terms share some common characteristics such as having a name and the ablity to store a single value.

Axioms contain terms which are never empty and have constant values. Templates contain terms which are typically empty until the first unification+evaluation step has been completed. Axioms and templates share an underlying implementation, but the role of axioms is to relay facts, while the role of templates is to analyse data and generate new facts in the form of axioms.

Examples of terms from the introduction are:

axiom city() {"bilene", 1718}

where "bilene" is a string literal and 1718 is an integer literal.

template high_city(name ? altitude > 5000, altitude)

where name ? altitude > 5000 is a variable with a an expression containing operators "?" and ">" and altitude is an empty variable.

Axiom terms

Axiom terms may be anonymous or named. The names are listed separately in the axiom declaration eg.

axiom city (name, altitude) {"bilene", 1718}

Use of named terms is recommended as it facilitates insertion of new terms amongst existing ones.

Template terms

Template terms have a large variety of formats reflecting the diverse operations allowed by eXPL. Terms intended to be included in the template solution must be named so their values can be accessed by consumers. Template terms are typically variables which can be referenced in expressions of other template terms.

There are two distinct roles a term can play in a unification+evaluation step:

  • Create a new fact. The term may be simply be set to the value of a unification axiom term or assigned to an expression containing one or more axiom terms.
  • Allow current unification step to be abandoned and proceed to the next iteration. This is called a "short circuit" and there are various term types that do this, such as comparison to a value or selection list.

Template terms can be characterised as empty or populated, typed or untyped and whether they evaluate an expression. Opposite are shown examples of the various possibilities.

Template Term Characteristics
altitude empty, untyped, no expression
integer altitude empty, typed, no expression
altitude = 1718 populated, untyped, no expression
integer altitude = 1718 populated, typed, no expression
integer x = y + 1 empty, typed, expression
name ? altitude > 5000 empty, untyped, expression

For more information on expressions and short circuits, go to eXPL Expressions.

Example

The following eXPL example shows cities from a list of world cities which are in a continent matching literal "Europe" - see the "euro_megacities" template "Continent" term.

Incidently, it also shows the use of inline comments and how an include statement is used to read an external axiom source:

// axiom mega_city
//   (Rank,Megacity,Country,Continent,Population)
// {1,"Tokyo","Japan","Asia",37900000}
// {2,"Delhi","India","Asia",26580000}...
include "mega_city.xpl";
template euro_megacities (Megacity, Country,
Continent { "Europe" });
query euro_megacities (mega_city : euro_megacities);

The tutorial3 EuropeanMegaCities code example runs this query. The solution when the query is run is:

Megacity = Moscow, Country = Russia, Continent = Europe)
Megacity = London, Country = UK, Continent = Europe)
Megacity = Istanbul, Country = Turkey, Continent = Europe)
Megacity = Rhine-Ruhr, Country = Germany, Continent = Europe)
Megacity = Paris, Country = France, Continent = Europe)