Skip to content

List expressions¤

The list is one of basic data structures provided by SP-Lang. The list contains a finite number of ordered item, where the same item may occur more than once. Items in the list must be of the same type.

Note

The list is sometimes also called inaccurately an array.


!LIST: List of items¤

Type: Implicit sequence, Mapping.

Synopsis:

!LIST
- ...
- ...

Hint

Use !COUNT to determine number of items in the list.

There are several ways, how a list can be specified in SP-Lang:

Example

!LIST
- "One"
- "Two"
- "Three"
- "Four"
- "Five"

Example

Implicit list using YAML block sequences:

- "One"
- "Two"
- "Three"
- "Four"
- "Five"

Example

Implicit list using YAML flow sequences:

["One", "Two", "Three", "Four", "Five"]

Example

The mapping form:

!LIST
with:
- "One"
- "Two"
- "Three"
- "Four"
- "Five"

!GET: Get the item from the list¤

Type: Mapping.

Synopsis:

!GET
what: <index of the item in the list>
from: <list>

index is an integer (number).

index can be negative, in that case, it specifies an item from the end of the list. Items are indexed from the 0, it means that the first item in the list has an index 0.

If the index is out of bound of the list, the statement returns with error.

Example

!GET
what: 3
from:
!LIST
- 1
- 5
- 30
- 50
- 80
- 120

Returns 50.

Example

!GET
what: -1
from:
!LIST
- 1
- 5
- 30
- 50
- 80
- 120

Returns the last item in the list, which is 120.