Navigation
Synopsis Reduce generated values to a single value.
Syntax ( Exp | RedExp | Gen1, Gen1, ... )
Description A reducer resembles the fold function found in most functional languages.

A reducer is equivalent to the following code:
it = Exp; 
for(Gen1, Gen1, ... ) 
    it = RedExp; 
it; 
and is executed as follows:
  • A fresh variable it is initialized with Exp (). We call the variable it since we use it to initialize the reducer, to make changes to it, and to return it as result.
  • A for loop iterates over all values produced by the generators Gen1, Gen1, ... ().
  • In the body of the loop, variable it is updated to reflect a new reduced value (). Note that it itself and variables introduced in Gen1, Gen1, ... may occur in RedExp.
  • The value of it is the result of the reducer.
Examples
rascal>L = [1, 3, 5, 7];
list[int]: [1,3,5,7]
rascal>(0 | it + e | int e <- L);
int: 16
rascal>(1 | it * e | int e <- L);
int: 105

Questions
Question [1]. Return the set of largest words.
Fill in
import Number;
import String;
text = ["Quote", "from", "Steve", "Jobs", ":", "And", "one", "more", "thing"];
public list[str] largest(list[str] text){
  mx = ( 0 | max(it, size(s)) | s <- text );
  return
    for(s <- text)
        if()
           append s;
}
and make the following true:
largest(text) == ["Quote", "Steve", "thing"];



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.