up previous next
2.5.2 List Constructors
These operators create new lists.
A..B
[A,B,C,...]
[X in L: LIST | Condn: BOOL]: LIST
[E:expression | X in L]: LIST
[E:expression | X in L: LIST and Condn: BOOL]: LIST
A..B creates the list of (consecutive) integers from A to B; both ends are included.

[A,B,C,...] makes a list containing the values A, B, C and so on, in that order. In particular, [] creates the empty list.

[X in L | Condn] makes a list of those elements in L for which condition Condn is true; the entries in L are considered in order.

[E | X in L] evaluates the expression E for each X in L, and collects the results in a new list; the entries in L are considered in order.

[E | X in L and Condn] evaluates the expression E for each X in L which satisfies the condition Condn, and collects the results in a new list; the entries in L are considered in order.

Example
/**/  [];  --> empty list
[]
/**/  1..4;
[1, 2, 3, 4]
/**/  [3,1,4,2];
[3, 1, 4, 2]
/**/  [N in 1..10 | IsPrime(N)];
[2, 3, 5, 7]
/**/  [N^2 | N in 1..4];
[1, 4, 9, 16]
/**/  [N^2 | N in 1..10 and IsPrime(N)];
[4, 9, 25, 49]