List

rascal-0.34.0

List values.

Syntax​

`[ Exp₁, Exp₂, ... ]`

Types​

//

`Exp₁``Exp₂`...`[ Exp₁, Exp₂, ... ]`
`T₁``T₂`...`list[lub(T₁, T₂, ... )]`

Description​

A list is an ordered sequence of values and has the following properties:

• All elements have the same static type.
• The order of the elements matters.
• A list may contain an element more than once.

The type of a list has the form `list[T]`, where `T` is an arbitrary type.

When a value or variable of type list occurs inside a list, that list value is inserted as list element. To achieve splicing of these elements, i.e., the insertion of the elements of the list value rather than the whole list, it has to be prefixed by the splice operator `*`.

The following operators are provided on list:

There are also library functions available for List.

Examples​

``rascal>[1, 2, 3];list[int]: [1,2,3]rascal>[<1,10>, <2,20>, <3,30>];lrel[int,int]: [  <1,10>,  <2,20>,  <3,30>]rascal>[1, "b", 3];list[value]: [1,"b",3]rascal>[<"a",10>, <"b",20>, <"c",30>];lrel[str,int]: [  <"a",10>,  <"b",20>,  <"c",30>]rascal>[["a", "b"], ["c", "d", "e"]];list[list[str]]: [  ["a","b"],  ["c","d","e"]]``

List splicing works as follows: by prefixing `L` by the splice operator, its elements are included as elements in the enclosing list:

``rascal>L = [1, 2, 3];list[int]: [1,2,3]rascal>[10, L, 20];list[value]: [  10,  [1,2,3],  20]rascal>[10, *L, 20];list[int]: [10,1,2,3,20]``