next up previous index
Next: Quantifiers Up: Expressions Previous: Filter expressions

Map expressions

   

MapExpression ::= 
  Expression "||" "["  Ident  "]" Expression |
  Expression "||"   Expression

A map expression expression takes a list as first parameter. For each of the elements of this list, it assigns the current element to the identifier indicated between brackets, and evaluates the second expression. The results of these evaluations are concatenated in a list that will be the result of the map expression.

If no identifier has been specified, using the second grammatical form, RainCode will use the predefined identifier X for this purpose. Hence, writing:

a := aList || [El] El + 1;

is equivalent to:

a := aList || X + 1;

RainCode defines a new scope for this free variable. Hence, there is no conflict in case of a local variable holding the same name as the free variable. RainCode will simply hide this conflictual declaration during the evaluation of the filter expression.

For instance,

{10, 20, 30, 1, 2} || X + 1

yields

{11, 21, 31, 2, 3}