|
| |||||||||
| Navigation |
Synopsis A list comprehension generates a list value.
Syntax
[ Exp1, Exp2, ... | Gen1, Gen2, ... ]
Types
Description A list comprehension consists of a number of contributing expressions
Exp1, Exp2, ... and a number of
generators Gen1, Gen2, Gen3, ... that are evaluated as described in Expressions/Comprehensions.
Examples Computing a list of squares of the numbers from 0 to 10 that are divisible by 3:
rascal>[n * n | int n <- [0 .. 10], n % 3 == 0];
list[int]: [0,9,36,81]
But we can also include the relevant n in the resulting list:
rascal>[n, n * n | int n <- [0 .. 10], n % 3 == 0];
list[int]: [0,0,3,9,6,36,9,81]
Questions
Question [1].
|