Saturday, June 14, 2008

C# Glorified : Nemerle!



Nemerle is a CLR based programming language. Just like C#. It works on .NET and mono. It can reuse libraries written with C# and vice versa. Basically it is C# glorified in my honest opinion. I've encountered nemerle a long time ago and it was quite matured since then. As a developer I was looking for more power and nemerle gave me what I want. It is definitely not a newbie language but is very very powerful. It is basically unification of C# and OCALM with enhanced macro support. Here are some features:

* Cross platform: Nermele is an open source CLR based language, it runs on mono / linux and .net platforms.

* C#/Java like syntax (statically typed): The syntax is similar to C#.


* Functional : Nemerle is functional.


* Macros : This is what makes nemerle very powerful. Basically it allows you to invent your own keywords. The language normally does not have constructs as if. But instead they are created as macros.

Here is how or a reverse loop implemented basically:

Code:
macro ReverseFor (i, begin, body)
syntax ("ford", "(", i, ";", begin, ")", body)
{
<[ for ($i = $begin; $i >= 0; $i--) $body ]>
}
then you can use this :

Code:
ford (i ; n) print (i);
You see! "ford" is on our own keyword.


* Type inference with Generics : Unlike C#/Java, this syntax works:
Code:
def d = Dictionary ();
d.Add ("Ala", 7);
foreach (s in args) {
...
}

* Builtin Design By Contract :
Code:
public Substring (startIdx : int) : string 
requires
startIdx >= 0
{ ... }
Here we say startIdx must be =>0 . Contracts are builtin!

Code:
public Length () : int ensures value >= 0
This ensures the property returns >= 0 values otherwise an exception is thrown (we can also customize that exception).


Code:
Class Vector [T] invariant position >= 0
{
private mutable position : int = 0;
....
Here, we say for the life time of this class , position can't be less than zero !

Speed : Ironically nemerle compiler is written with nemerle itself which is CLR language. Because of Runtime JIT'ing the speed is somewhat close to (average about 80% levels) to native C code.

* Interop : nemerle can interop with any CLR language. You can use windows.net libraries or mono libraries, you can intermix your code (in seperate assemblies of course ) with C# or you can reuse your nemerle libraries from C#

For more details go to here: http://nemerle.org/Features

2 comments:

Anonymous said...

beach eurartekin suspect counterparts pdfinstitute severe diary disclosures learnt hernia cruel
lolikneri havaqatsu

Unknown said...

"Builtin Design By Contract"

This feature is implemented as macro too.