![]() |
|
Navigation |
Synopsis Count words in a line.
Examples Here is a clever, albeit rather dense, solution that illustrates several Rascal concepts.
module demo::common::WordCount::CountInLine3 public int countInLine3(str S){ return (0 | it + 1 | /\w+/ := S); }We use a Rascal:Reducer that is a recipe to reduce the values produced by one or more generators to a single value:
rascal>import demo::common::WordCount::CountInLine3; ok rascal>countInLine3("Jabberwocky by Lewis Carroll"); int: 4 ![]() |