ncc 0.9.3

Version of implementation Nemerle of programming language Nemerle

A version of ncc compiler, released on May 16th, 2006.

Examples:

Hello, World! - Nemerle (295):

This example is written in C# style; a more compact version would be just

System.Console.WriteLine ("Hello, World!");
class Hello {
  static Main () : void {
    System.Console.WriteLine ("Hello, World!");
  }
}

Fibonacci numbers - Nemerle (296):

This example uses recursive definition of Fibonacci numbers, expressed in functional style. Note the definition of loop counter i — keyword mutable, as opposed to regular def, means that the value of the variable is going to change.

def fib(i)
{
  | x when x<2 => 1
  | _          => fib(i - 2) + fib(i - 1)
}
 
mutable i=0;
while (i<16)
{   System.Console.Write("{0}, ", fib(i));
    i++;
}
System.Console.WriteLine("...");

Factorial - Nemerle (297):

This example uses recursive factorial definition; tail recursion is optimized by the compiler to become a loop. Note that the default data type is int, so trying to calculate 13! results in overflow error:

Unhandled Exception: System.OverflowException: Number overflow.
def fact(i)
{
  | 0 => 1
  | other => other * fact(other - 1)
}
 
for (mutable i=0; i<16; i++)
    System.Console.WriteLine("{0}! = {1}", i, fact(i));