Lists in eXPL contain ordered sequences of basic type values, terms or axioms. A list can be declared to contain items of one specific basic type. such as integer or string, or the terms of a single axiom or a collection of axioms. There are a total of seven list types, which were introduced in the Lists application of tutorial3. There are 5 basic type lists, which are described here, and the remaining lists relating to axioms are treated separately as they have special characateristics.
These are the aspects of lists to be covered:
- Declaration
- Export
- Access
- Navigation
List Declaration
A Basic Type List declaration has format:
list<type> name [ = {
initializer-list}]
The optional initializer-list is a comma-delimited sequence of values or expressions used to populate the list. Type conversion is supported. for example, a decimal list is initialized here with formatted number string literals:
"-9,223,372,036,854,775,808" };
A list declaration cannot be located as a template term but it can be attached to a template using a plus sign. Here is an example where an attached list declaration which creates a list of dice face values:
+ list<integer> dice = { 1, 2, 3, 4, 5, 6 };
(
dice[0], dice[1], dice[2],dice[3], dice[4], dice[5]
);
An attached list is not visible outside the template, but can be exported to the query result by using the export modifier.
List Range
Another option is to declare a list with range values that define a start offset and a limit to how big the list can grow:
list<type> name ( start,end )
The "start" value is first valid index value and "end" is the last valid index value. When a range is set, then an item can be inserted at any location within the range. Without a range set, a list can only grow by appending items to the end of it. Care must be used when a range is set as a list will contain empty locations unless/until the program fully populates it.
Application AssignMarks of tutorial6 shows a list with range of 1 to 18 initialized in reverse order so the alphabetical items it contains are arranged in descending order. Without the range, the only choice is ascending order.
In DeclareMarks application of tutorial6, a blank item is placed at the start of a declaration initializer list to a achieve an effective range starting at 1.
Export
When an eXPL query is executed, a result object is returned containing all exported artifacts. Declared lists are not normally exported,
but this can be changed for a particular list by using modifier export at the start of it's declaration.
The list is made available by the result object using type-specific methods eg. to get the dice items of the previous example,
you could use decimalIterator to iterate through the list from start to end.
Here is an example of list named "amount_list" declared with the export modifier:
+ export list<currency> amount_list;
...
