Expression Pattern Language (eXPL)

eXPL Value and Term Lists

There are three types of lists in eXPL:

  • Value Lists
  • Term Lists
  • Axiom Lists

Value List items are of a single type, while Term List items are the terms of a backing axiom and therefore can be of mixed types. Axiom lists, described here,

Value Lists

A value list declaration has format: list<type> name. eg.

list<string> mark;

This is a list of alphabetical scores from "a+" to "f-" which appears in the example below.

A list starts out empty and is populated by assigning items to it. The valid index ranges starts from zero, but the list can start with any positive number and be populated non-contiguously.1 There are 3 possibilities how to reference a value list:

  1. use an integer literal eg. mark[0]
  2. use a variable containing an integer value eg. mark[english] where "english" is an integer
  3. use an expression which evaluates to an integer value eg. mark[i++]

The variable index is handy as the it's value can be provided by unification. Here is an example where numerical grades are converted to alphabetical marks using unification and a list:

axiom grades (student, english, maths, history)
{"George", 15, 13, 16}
{"Sarah", 12, 17, 15}
{"Amy", 14, 16, 6};
list<string> mark;
mark[0] = "f-";\
mark[1] = "f";
...
mark[16] = "a";
mark[17] = "a+";
template score(student, mark[english], mark[maths], mark[history]);
query marks(grades : score);

The tutorial6StudentScores code example which runs this query. The solution when the query is run is:

George, mark_english = a-, mark_maths = b, mark_history = a
Sarah, mark_english = b-, mark_maths = a+, mark_history = a-
Amy, mark_english = b+, mark_maths = a, mark_history = d-

Term Lists

A Term list wraps an axiom so it can be accessed by array notation. The declaration format: list<term> name(axiom-to-wrap). eg. in the opposite example Term list color wraps axiom swatch

axiom swatch (name, red, green, blue)
{"aqua", 0, 255, 255}
{"black", 0, 0, 0)}
{"blue", 0, 0, 255};
list<term> color(swatch);

Here is a query which utilizes the color list:

template shade(name, color[red], color[green], color[blue]);
query colors(swatch : shade);

The tutorial6 Colors sample runs this query. The solution is:

aqua, color_red = 0, color_green = 255, color_blue = 255
black, color_red = 0, color_green = 0, color_blue = 0
blue, color_red = 0, color_green = 0, color_blue = 255

Each item in the list corresponds to a term in the axiom. There are 4 possibilities how to reference a Term list:

  1. use an integer literal eg. color[0]
  2. use the name of a term (which requires the axiom not have anonymous terms) eg. color[green]
  3. use a variable containing an integer value eg. color[(green)]2
  4. use an expression which evaluates to an integer value eg. color[i++]

Three particular uses of a Term list are;

  1. As a convenient substitute for a value list - it easier to initialize and the items can be named.3
  2. As the second dimension of an Axiom list which is described here.
  3. To modify axiom term values, which are otherwise read-only.4
A term list can refer to an axiom that is declared after the term list is declared

Notes

  1. Beware that a value list will allocate memory to contain the highest index in use and all values in between.
  2. Wrap a variable name in parentheses to indicate it is not a term name. See tutorial6 Gaming
  3. See tutorial6 StudentScores2
  4. See tutorial6 BlackIsWhite