Nemerle
Implementation of programming language NemerleCompiler for Nemerle language. ncc tool allows working from command-line. Nemerle Studio is a fully functional IDE based on Visual Studio 2008 Shell. Alternatively, the compiler can be integrated with Visual Studio itself.
Links:
Examples:
Hello, World!:
Example for versions ncc 0.9.3This 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:
Example for versions ncc 0.9.3This 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:
Example for versions ncc 0.9.3This 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));
Comments
]]>blog comments powered by Disqus
]]>