Rowan home > Reference > Each

Each: ¨

Module: Main
Syntax: fn ¨ noun
   or noun ¨ :Invocation noun
   or noun :Invocation ¨ noun
   or noun ¨ :Invocation ¨ noun
Errors: none
Keystrokes: Ctrl+1

Runs the function or invocation on each element of noun. For functions ¨ is a shortcut for ^1, to save some typing and parentheses:

   +/¨⍳4 5
Result: (10 15 )
   (⍳2 3),¨(⍳4 5)
Result: ((1 2 1 2 3 4 ) (1 2 3 1 2 3 4 5 ) )

For an invocation, ¨ allows you to call a method on each element of a vector argument. For example:

   sv←"Hello" "there" "wonderful" "world"
Result: (Hello there wonderful world )
   sv¨:Length
Result: (5 5 9 5 )
   sv¨:Substring(2, 2)
Result: (ll er nd rl )

You can also put the ¨ after the invocation, in which case the .Net call is run with the parameter list being each time one element from the noun on the right:

   128:ToString¨("X8" "X4")
Result: (00000080 0080 )
   $Math:Cos¨ 0.01×⍳10
Result: (0.999950000416665 0.999800006666578 0.999550033748988 0.999200106660978 0.998750260394966 0.998200539935204 0.99755100025328 0.996801706302619 0.995952733011994 0.995004165278026 )
   $Console:WriteLine¨("Rowan 1.0" "---------")
No result
Because of the way ¨ is parsed, you must parenthesise the vector on the right, otherwise your code will not do what you expect.

And finally, you can put an ¨ on both sides of the invocation, in which case Rowan loops through both the noun on the left and the noun on the right, producing a depth-2 vector of results:

   sv¨:Substring¨(1 4) 2;
Result: ((ello llo ) (here ere ) (onde nderful ) (orld rld ) )
// i.e. (sv¨:Substring(1 4)),¨(sv¨:Substring 2)
   (128 192 256 32768)¨:ToString¨("X4" "F1")
Result: ((0080 128.0 ) (00C0 192.0 ) (0100 256.0 ) (8000 32768.0 ) )