This is the reference for Rowan.net version 1.2. Each # function has a link describing its full syntax, exceptions it can throw, and functionality. Symbols which need a special key combination to enter show what to type to get them with the default keyboard map.
i
: Integer (e.g. 3
or [1 4 2]
).
n
: Floating point number. An integer may also be passed.
x
: Extended precision number. An integer or a float can be passed in most cases.
c
: Character scalar. Entered as 'a'
str
: String. A character scalar may be used instead. Entered as "hello world!"
block
: Function block. Entered as { blockdef }
.
Function blocks may be nested.
array
: An array which can contain elements of any type, including other arrays. Entered as [item1 item2 ... itemn]
.
bool
: Boolean. Also, a numeric may be used in a control test; it must be scalar and will be compared with 0 (false).
class
: A reference to a .Net class, e.g. $Console
. You can reference types in the mscorlib
assembly, or any assembly you have referenced with #addassembly
. Type names can be shortened with #using
.
object
: An instance of a .Net class, e.g. #new $IO.FileInfo("test.txt")
.
i, n and c type arguments can also be an array type argument, every atomic member of which is of the appropriate type (i, n or c). obj
is used to mean any stack item. is
, ns
and cs
are used where a vector type is invalid.
Types nv and cv no longer exist, as they once did in R (treated as arrays). Types i and n can now be vector. Also [1 2 3] will be of type (Integer | Vector), i.e. an integer vector, although it may be passed where array
is required. (See #type
for details.)
All functions which take one or more extended-precision arguments on return an extended-precision value if one is passed. In general, the return type of a function is that of the ‘widest’ of its arguments.
⍺
(AltGr+A) and ⍵
(AltGr+W) are not functions, they are read-only names within a user-defined function and are treated as nouns by the interpreter.
⌊ n : n
(AltGr+F): Round down to nearest integer.
⌈ n : n
(AltGr+Shift+F): Round up to nearest integer.
- n : n
: Negation.
÷ n : n
(AltGr+D): Reciprocal.
* n : n
: e (2.718...) to the power of the argument.
√ n : n
(AltGr+Shift+R): Square root.
⍟ n : n
(AltGr+8): Log to base e.
∑ n : n
(AltGr+Shift+S): Sum.
∏ n : n
(AltGr+Shift+P): Product.
, any : array
: If any
is an array, return it unchange, otherwise create a one-element array containing it.
< any : array
: Box any
, that is create a one element list containing it.
∊ any : vec
(AltGr+E): Enlists the array, flattening its internal structure and making it a vector. The enlist of a scalar is also a vector.
⍋/⍒ array: i
(AltGr+G, AltGr+Shift+G): Returns the indices that will sort array
: (⍋array)⌷array
will be the sorted array. You can also use grade dyadically, in which case the left argument is sorted by the right.
↑ array
(AltGr+Y): The first item in the array.
↓ array
(AltGr+U): All but the first item in the array.
⌽ array
(AltGr+Z): Reverse the array.
⍉ array
(AltGr+X): Transpose the array.
∪ array
(AltGr+Shift+C): Unique elements of the array.
Miscellaneous functions; default level 0 unless otherwise stated:
⍳ i : iv
(AltGr+I): The numbers from 1 to i
. Default level -1.
= any : any
: Displays the contents of any
.
⍴ any : i
(AltGr+R): The length of any
.
≡ any : i
(AltGr+Shift+Minus): The depth of any
.
⍕ any: str
(AltGr+N): The string representation of any
.
⍏/⍖ any : any
(AltGr+Shift+Y, AltGr+Shift+U): Promote and demote numeric types. Default level -1.
⌹ n : n
(AltGr+Shift+D): Matrix inverse. Default level -3.
x + x: x
: Addition.
x - x: x
: Subtraction.
x | x: x
: Difference (i.e. 2|5
and 5|2
are both 3).
x × x: x
(AltGr+T): Multiplication.
x ÷ x: x
(AltGr+D): Division; always returns n
or x
.
x % x: x
: Modulo.
n * n: n
: Power: 2*3
gives 8
. Can also take an extended precision left argument and an integer power (right argument): 2`*3
is 8`
.
n √ n : n
(AltGr+Shift+R): nth root; e.g. 3√64
gives 4
.
n ⍟ n : n
(AltGr+Shift+O): Log to base n; e.g. 2⍟32
gives 5
.
x ⌈/⌊ x : x
(AltGr+Shift+F, AltGr+F): Largest/smallest of the arguments.
x </>/≤/≥ x : bool
(AltGr+Comma, AltGr+Dot): Conditional operators for numerics.
Logical functions:
obj obj =/≠/≡/≢ : bool
(Equal, AltGr+Equal, AltGr+Minus, AltGr+Shift+Minus): Equality operators.
i ∧/∨ i : i
(AltGr+L, AltGr+K): Bitwise And and Or. bool ∧/∨ bool : bool
produce the logical And and Or. Note: the symbol for And (∧
) is not the ASCII caret ^
(Shift+6 on many keyboards).
Array functions:
i ↑ any
(AltGr+Y): Take the first i
items from any
. Negative takes from the back.
i ↓ any
(AltGr+U): Drop the first i
items from any
. Negative drops from the back.
any ∊ array
(AltGr+E): Is any
in array
? Default level (-1 0).
any ⍸ array
(AltGr+Shift+I): What position is any
in array
? Default level (-1 0).
i ⍴ any
(AltGr+R): Reshape any
to be of length i
, repeating if necessary.
i ⌽ array
(AltGr+X): Rotate the array by i
elements. Default level (-1 0).
array ∩/∪ array
(AltGr+Shift+V, AltGr+Shift+C): Intersection and union of the two arrays (i.e. items in both/either of them).
array ⍋/⍒ array: i
(AltGr+G, AltGr+Shift+G): Returns the left argument sorted by the right.Miscellaneous functions:
inx ⌷ array
(AltGr+S): Indexing, 1-origin.
name ←/⍅ any : any
(AltGr+[, AltGr+Shift+[): Local and global assignment.
#addassembly str
: Adds a .Net assembly to the local cache.
#delegate type fn
: Creates a delegate, for use as an event handler.
#erase str
: Erases an object.
#if cond { block }
: Executes block
if cond
is true. Can be followed by #elseif
and #else
.
#new type obj
: Creates a new object of type type
with constructor arguments in obj
#pop i
: Remove i
levels from the dictionary stack. Useful for ‘escaping’ from a suspended function.
#run str
: Loads and runs a script. Assumes the extension *.rws if none given.
[ names ] #save str
: Saves the current state in a script. If you pass names
, it is an array of names of items to be saved (either String[] or R.Name[]); if you don't, Rowan tries to save all objects. Note that some objects (.Net Objects, defined functions (g⍅+
)) are not savable and will cause an error.
#try { block }
: Run block
testing for exceptions; followed by #catch
and/or #finally
.
#type obj
: Gets the Rowan type code for the object.
#using str
: Uses a .Net namespace.
There are also some subsidiary # functions in control structures which are always linked to one of those above:
#catch type { block }
: see #try.
#else { block }
: see #if.
#elseif cond { block }
: see #if.
#finally { block }
: see #try.
Operators and conjunctions modify the way other functions work. Operators have either one or two functions as their arguments, and conjunctions have one function and one noun. The functional arguments are signified by fn
, dfn
for a dyad only and mfn
for a monad only.
fn1 ⌾ fn2
(AltGr+Shift+O): Provides a custom internal method fn1
for fn2
.
fn ^ i
: Change the level of fn
. If i
is scalar, all three levels (monadic, left and right) are set; if a two element vector, the left and right levels are set. For more information, see About Level. Some common level-set expressions have one symbol shortcuts:
¨
(Each, AltGr+Semicolon) is equivalent to ^1
⊢
(Each Right, AltGr+9) is equivalent to ^(0 1)
⊣
(Each Left, AltGr+0) is equivalent to ^(1 0)
⍩
(All, AltGr+Shift+Semicolon) is equivalent to ^-1
dfn ⍨
(AltGr+Shift+#): Reverse or duplicate the arguments.
dfn ∙ dfn
(AltGr+Shift+Dot): Create an inner product function which is similar in style to the matrix product function from two dyads.
fn ¨ noun
or noun ¨:Invocation
(AltGr+Semicolon): Runs the function or invocation on each element of noun
.
dfn / or \
: Create a monadic reduction function equivalent to inserting dfn
between each element of its argument.
dfn ⎕
(AltGr+Q): Create a dyadic tabling function from the dyad dfn
.
dfn ⌶
(AltGr+Shift+T): Modify dfn
so that instead of returning a boolean vector, it returns the integer indices where there would have been True values.
#cs
(String): Current namespace. Assignment to #cs
sets the current namespace relative to its present location.
#debuglevel
(Integer): Controls the level of debug information emitted by the interpreter.
#engine
(Object, Read-only): The currently active interpreter.
#exception
(Object, Read-only): In a catch block, the exception caught.
#null
(Null, Read-only): A null.
System.ArgumentException
: An argument to a function had an invalid value.
R.ContextException
: The requested action is not valid in this context.
System.FormatException
: Thrown by the tokeniser if a token could not be parsed.
System.IndexOutOfRangeException
: Array index out of bounds.
System.InvalidCastException
: Type mismatch.
R.LengthException
: Arguments different lengths, or wrong length.
System.MissingMemberException
: A token on the stack could not be resolved.
R.MissingSystemTokenException
: An unknown primitive or # function was called.
RedCorona.Rowan.SyntaxException
: The interpreter could not work out how to execute an expression.
RedCorona.Rowan.IRowanPlugin
interface (defined in RowanCore.dll) will be loaded. The standard Rowan installation includes various plugins, which will be in your RowanPlugins directory already. Missing plugins can cause scripts not to load, as the tokeniser will throw a R.MissingSystemTokenException
for unknown interpreter features.