Rowan can be used from the .Net Framework, by passing Rowan code to the engine from your C# code, and you can use the .Net Framework from Rowan too. This page shows you how to do both.
Functions defined in the basic .Net Framework libraries are available to you with no effort, using the colon syntax, which looks very similar to the equivalent C# calls:
Rowan:You can see how the names of types are preceded by a $ sign, and colons are used instead of dots to separate the object or type from the method or property name. The first of these is to keep Rowan clean of reserved words (the only ones ares←300:ToString("X");
C#:String s = 300.ToString("X");
Rowan:
worldString←"Hello, world!":Substring(7 5);
C#:String worldString = "Hello, world!".Substring(7, 5);
Rowan:
#using "System.Drawing";
(at top of file) ...p←#new $Point(30 40);
C#:using System.Drawing;
(at top of file) ...Point p = new Point(30, 40);
true
and false
); the second, to make it clear which dots are merely namespace delimiters and which are important syntax elements (the ones Rowan uses colons for). Objects are created with #new
, and parameter lists are arrays with each level-1 element corresponding to one argument.
Of course a lot of .Net code is inherently serial, and so you can't make best use of Rowan's array capabilities. For example, the code to load a file has to loop just like its C# counterpart:
#try { sr←$IO.File:OpenText(⍵); res←[""]; #while{true} { thisline←sr:ReadLine(); #if(thisline≡#null) { #break } #else {res,←thisline} } } #catch $IO.FileNotFoundException { ⍇"File "+⍵+" was not found"; } #finally { sr:Close(); };
If you want to shorten a name, you can use #using "System.Drawing"
; if Rowan can't find a type it tries prepending all the strings you've used like this in turn. (The System namespace is automatically 'used'.)
To use a .Net method on members of a vector, you can use the ¨
pseudo-operator:
sv←"Hello" "There" "Wonderful" "World"; sv¨:Substring(2 2); Result: (ll er nd rl ) $Math:Sin¨ 0.1×⍳5 Result: (0.0998334166468282 0.198669330795061 0.29552020666134 0.389418342308651 0.479425538604203 )If you're using .Net functions or properties which do indexing, remember that the Framework uses zero-origin indexing while Rowan (in its default state) uses 1-origin.
You can use your own assemblies easily too. Just tell Rowan to load the assembly using #addassembly "MyAssembly.dll"
; you can either supply the assembly name if it is in the GAC or on the path, or a path to the file containing it. Once you've done that, your code is available in just the same way as the rest of the Framework, although you'll probably want to use #using "MyAssembly.Components"
to use the namespace.
This section is for those who want to write their application predominantly in C#, or another .Net language, and use Rowan for occasional array manipulations.
The information on this site is based on this article which appeared in the Spring 2005 edition of Vector.