Skip to content

Tuple expressions¤

The tuple is one of basic data structures provided by SP-Lang. A tuple is a collection of items, possibly of different types.


!TUPLE: A collection of items¤

Type: Mapping.

Synopsis:

!TUPLE
with:
  - ...
  - ...
  ...

There is no limit of the number of items in the tuple. The order of the items is preserved.

Example

!TUPLE
with:
  - John Doe
  - 37
  - 175.4

Example

Use of the !!tuple notation:

!!tuple
- 1
- a
- 1.2

Example

Even more concise version of the !!tuple using flow syntax:

!!tuple ['John Doe', 37, 175.4]

Example

Enforce specific type of the item:

!TUPLE
with:
  - John Doe
  - !!ui8 37
  - 175.4

Item #1 will have a type ui8.


!GET: Get the item from a tuple¤

Type: Mapping.

Synopsis:

!GET
what: <index of the item>
from: <tuple>

what is an integer (number), it represent the index in a tuple. what 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 what is out of bound of the list, the statement returns with error.

Example

!GET
what: 1
from:
  !TUPLE
  with:
    - John Doe
    - 32
    - 127.5
Returns `32`.

Example

Using the negative index of items:

!GET
what: -1
from:
  !TUPLE
  with:
    - John Doe
    - 32
    - 127.5

Returns 127,5.