Factorial in Nemerle

Example for versions ncc 0.9.3

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));