next up previous index
Next: Map expressions Up: Expressions Previous: & operator

Filter expressions

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

A filter 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, referred to as the ``filter expression''. This evaluation must yield a boolean value. The result of the filter expression is a list made of all the elements of the original list for which the filter expression did yield TRUE.

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 > 0;

is equivalent to:

a := aList |  X > 0;

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.