Expression Pattern Language (eXPL)

Term Behaviour and Attributes

Behaviour

Terms are the elements contained in axioms and templates. All terms share a common interface for the sake of unification pairing, which allows terms to identify themselves, set and get a value and unify with other terms with the same name. Axiom term values are always constants while Template terms may have constant or variable values according to how they are used in expressions. The only eXPL variables are template terms as there is no "new" operator or any other means to create ad hoc variables. As execution proceeds in iterative cycles, it is essential for a variable to have a modification version so when execution reverses back to a previous iteration, the variable is cleared only if it has the most recent modification version. In fact all template terms have a modification version and the value zero indicates a template term should never be cleared, or in other words, it is a constant.

Traits

There are three traits that characterise terms:

  1. type
  2. status
  3. structure

Axiom terms are always characterised as having a non-empty status, a simple structure and a fixed type, that is, the type cannot be modified after the axiom is created. Axiom term type is also constrained in that when an axiom is a member of a collection, the type is fixed at every term position.

Template terms can have any combination of traits and both type and status can be changed during program execution.

Type

Types can be basic, like integer, boolean, string ... or modular, like axiom, list ... or unknown, which means unable to participate in any operations.

Basic Types
eXPL TypeExample
string"Australia"
integer16498
double11230.9845
booleantrue
decimaldecimal(11230.9845)
currencycurency("$1234.56")

string corresponds to Java java.lang.String class. Backslash '\' is used as an escape character the same as in Java.

integer, double and boolean correspond to Java primitive types long, double and boolean respectively.

Modular Types

Modular types include basic lists eg. list<string> for a list of strings, axioms, list of axioms and list of axiom terms, which is represented by list<term>. All lists can be accessed randomly for read and write operations with variables which use array [] notation.

Unknown Type

The "unknown" type applies to objects of an unsupported type obtained from an external source. Terms with such objects cannot participate in operations with other terms other than assignment. A template term can also be declared without specifying type, in which case, the type will default to "unknown" until a value is set.

Note that when term type is specified, this is regarded as a variable declaration, not a reference to a variable. When a term is declared, then it cannot be referenced before the declaration, or a duplication error results.

Currency Type

The currency type has features which make it useful for performing operations with amounts and supports internationalization. It has the following features:

  • The region to which a currency applies can be specified in the declaration
  • The curreny type will automatically convert amounts in text format to corresponding decimal values
  • The type of rounding performed on multiplication and division suits financial transactions

A currency declaration has format:

currency [ $ region ] name

The optional region specification can be a ISO code literal eg. "US" for the USA or "fr_LU" for French Luxenburg. Region can also be a variable eg currency $ country. This variable is included in the solution. Application MultipleCurrencies of tutorial3 demonstrates currency specified with a region variable used to convert amounts from a large number of regions to decimal values. Note the imported world_currency.xpl file is in the tutorial main resource location.

Status and Structure

A term can have status "empty" or "non-empty" while structure can be "simple", "compound" or "composite". Here are examples of various template term characteristics prior to unification. Post unification/evaluation, all empty terms are expected to be non-empty, otherwise the program is likey to fail. Note that the last 3 examples are declarations because type is specified:

Template TermCharacteristics - empty/complexity
altitudeempty, simple
altitude = 1718non-empty, compound
name ? altitude > 5000empty, composite
integer altitudeempty, simple
integer altitude = 1718non-empty, compound
integer x = y + 1empty, composite

From the examples you can see compound structure refers terms which are initialized to a literal value. Any other type of expression requires a composite structure to evaluate a value. The compound terms can also be set by unification and this then overrides the assignment stated in the program.

Types Examples

The Types application of tutorial3 runs a query which simply unifies an axiom with a template and displays the solution on the console. What is interesting is that each axiom has a different type and you get to see what Java class corresponds to each type. You will also observe macros used to create literal values for types which cannot be represented symbolically: decimal, currency and unknown.

The Lists application of tutorial3 demonstrates all seven of the eXPL list types. For each type there is a list declaration and a template which contains the list items and the size of the list. This application does not run a query as it is easier, in this case, to access each template directly. Note that the last list, the axiom list, is accessed as a 2-dimensional array to get the first term of each axiom in the list.