This is the introduction to Rowan. See getting started for a simple starter kit, or for detailed information on functionality, see the Rowan Reference.
Rowan is free for non-commercial use. That means you can download it, play with it, develop with it and incorporate it in your own projects, as long as you don't make money out of my hard work!
Rowan uses APL-like syntax (one symbol can be a function, a conjunction or an operator), and executes by default from right-to-left. Semicolons separate statements; new-lines are treated in the same way as other white space and have no special meaning. For detailed information about the syntax, see the Language Elements documentation.
A function in Rowan can be niladic, monadic or dyadic (0, 1 or 2 arguments), with the arguments being passed on the right (the first argument, ⍵
) and the left (the second argument, ⍺
). In most cases, either argument may be an array (see the Reference for details on individual functions): (2 3)+4
. Rowan includes a large number of built-in functions, most of which are one symbol and the rest of which start with a #
.
You can create your own functions by enclosing code in curly brackets:
avg←{(+/⍵)÷⍴⍵} avg (2 4 5) Result: 3.66666666666667Your functions can also be niladic, monadic or dyadic: if you use
⍺
within your code (the left argument) then it is a dyad, if you only use ⍵
then it is a monad (as avg
is) and if you use neither then it is a nilad. Once defined, your own functions can be used anywhere a built-in Rowan function of the same type can.
Functions can also be un-named, if they are only short snippets which you don't want to re-use. For example, if you only wanted to do averaging in one place in your code, you could run the function directly without giving it a name:
{(+/⍵)÷⍴⍵}(2 4 5); Result: 3.66666666666667
Named Arguments. A function may have a header section, which declares named arguments, for both monadic and dyadic cases. For example:
f←{⋄ x: x²} f 4 Result: 16 g←{l ⋄ r: l×r } 6 g 7 Result: 42If more than one named argument is provided on either side, the parameters passed to the function are split up into the names you provide. If there are the wrong number of parameters, an exception will be thrown:
f←{⋄ x y: x+y } f 6 7 Result: 13 f 6 7 8 R.LengthException: Argument list length (2) not equal to passed args ((3 4 5 ):3) ...If the function is monadic, you can omit the
⋄
and simply provide the argument list:
{x: x²} 6 7 Result: (36 49) {x y: x+y} 6 7 Result: 13The header section must be on the first line, must contain nothing but names and an optional
⋄
(to represent the function being called). It ends with a bare colon; in the examples above the space after the colon is essential (otherwise the parser would see :x
as an invocation), and you should always put a space or a new line after the colon (although any non-alphabetic character will work).
Multi-Statement Functions. Statements in a Rowan function are separated by semicolons. Each statement is executed (from right to left) in turn, unless a statement contains an immediate return (monadic ←
) in which case the function is terminated. The result of a function, when it is terminated or reaches its natural end, is the result of the last statement which returned a value.
For example:
f←{ x y : temp←x²; // would return x², if it were the last statement y+temp; // would return y+x², if it were the last statement ←10; // returns 10 and exits "Hello, world" // never reached }
Because Rowan is built using .Net tools, it is easy to call out to other parts of the framework. See Using .Net for details. You will also be able to compile most Rowan to C#, in a similar way to R, in a future version.
Rowan has full .Net exception handling capabilities using the functions #try
... #catch
... finally
. This gives you the same options for exception handling as in C#; you can also use #throw
to signal an error.
The information on this site is based on this article which appeared in the Spring 2005 edition of Vector.