Wednesday, July 15, 2009

Wild - C# on My Mac

Install mono and after just a few clicks the mono compiler awaits your code.
using System;
 
public class HelloWorld
{
 static public void Main ()
 {
  Console.WriteLine ("Hello World");
 }
 
}
[greg:~] cd dev/src/mono
[greg:mono] gmcs Hello.cs
[greg:mono] ls
Hello.cs Hello.exe
[greg:mono] mono hello.exe
Hello World
[greg:mono] 

Now, how do I get F# to run?  Download the zip file from the F# home page and, just as before, execute the exe file by entering the mono fsi.exe command which puts the terminal session in mono mode.
> let buf = System.Text.StringBuilder("Coding");;

val buf : System.Text.StringBuilder = Coding

> buf.Append(" F# is F#un");;

val it : System.Text.StringBuilder =
  Coding F# is F#un {Capacity = 32;
                     Chars = ?;
                     Length = 17;
                     MaxCapacity = 2147483647;}

> buf.ToString();;
val it : string = "Coding F# is F#un"
> 
Note:The second semi-colon is significant.

In this code, the declared variable is untyped.  I think Venkat Subramaniam would tell us of its similarities to VB.  By the way, see Venkat's videos here.