Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
service
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
Freenet DSL
Who's Online
19 user(s) are online (15 user(s) are browsing encyclopedia)

Members: 0
Guests: 19

more...
partner

Nemerle

Nemerle is a high_level_language static_typing programming language for the Microsoft_.NET (see also mono_development_platform) platform. It offers functional_programming, object-oriented and imperative_programming features. It has a simple c_sharp_programming_language-like syntax and a powerful meta-programming system.

It was developed at the Wroclaw University (Poland) by Kamil Skalski, Micha Moskal, Prof. Leszek Pacholski and Pawe Olszta. It has been named after the mage Nemmerle from A Wizard of Earthsea by Le_Guin,_Ursula_Kroeber (spelling with a single m is a design decision).

=Features=

Probably the most important feature of Nemerle is the ability to mix object oriented and functional_programming programming styles. The top-level program structure is object oriented, while in the body of methods one can (but is not forced to) use functional style. This is very handy in some programming problems. The feature set here include Delegates_(programming), algebraic_data_types and pattern matching.

Another very important feature is taking a high_level_language approach in all aspects of the language - trying to lift as much of the burden from the programmer as possible. Features like meta-programming and type inference fit here.

Features that come from the functional land are algebraic_data_types (aka algebraic data types), pattern matching, type inference and generic_programming (aka generics). The meta-programming system allows great Compiler extensibility, embedding domain specific languages, partial evaluation and aspect_oriented_programming programming.

Last but not least - the usage of more mundane library stuff from the Microsoft_.NET is as easy as (or easier than) in c_sharp_programming_language.

=Examples=

==Hello, World!==

The traditional Hello world program can be implemented in a more C-like fashion:

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

or more simply:

System.Console.WriteLine( Hello, world! );

==Examples of macros==

Macros allow you to have boilerplate code generated for you under the hood, with additional static checks performed by the compiler. They give you the power to programatically generate code.

===Database accessibility===

For example, using Nemerle macros for SQL you can write:

ExecuteReaderLoop ( SELECT firstname, lastname FROM employee WHERE firstname = $myparm , dbcon, { System.Console.WriteLine ( Name: {0} {1} , firstname, lastname) });

instead of

string sql = SELECT firstname, lastname FROM employee WHERE firstname = :a ; NpgsqlCommand dbcmd = new NpgsqlCommand (sql, dbcon, dbtran); dbcmd.Parameters.Add( a , myparm); NpgsqlReader reader = dbcmd.ExecuteReader(); while(reader.Read()) { string firstname = reader.GetString (0); string lastname = reader.GetString (1); System.Console.WriteLine ( Name: {0} {1} , firstname, lastname) } reader.Close(); dbcmd.Dispose();

and this is not just hiding some operations into a library, but additional work performed by compiler to understand the query string, variables used there, and columns returned from the database. The ExecuteReaderLoop macro will generate code roughly equivalent to what you would have to type manually. Moreover, it connects to the database at compilation time to check that your SQL query really makes sense.

===New language constructs===

With Nemerle macros you can also introduce some new syntax into the language:

macro ReverseFor (i, begin, body) syntax ( ford , ( , i, ; , begin, ) , body) { = 0; $i--) $body ]> }

defines a macro introducing the ford (EXPR ; EXPR) EXPR syntax and can be used like

ford (i ; n) print (i);

==Nemerle with ASP.NET==

Nemerle can be either embedded directly into ASP.Net: Page_Load(_ : object, _ : EventArgs) : void { Message.Text = $ You last accessed this page at: $(DateTime.Now) ; } EnterBtn_Click(_ : object, _ : EventArgs) : void { Message.Text = $ Hi $(Name.Text), welcome to ASP.NET! ; } Please enter your name: < p>

or stored in a separate file and entered with a single line:

==PInvoke==

Nemerle can take advantage of native platform libraries. The syntax is very similar to c_sharp s and other Microsoft_.NET languages. Here is the simplest examlple:

using System; using System.Runtime.InteropServices; class PlatformInvokeTest { [DllImport( msvcrt.dll )] public extern static puts(c : string) : int; [DllImport( msvcrt.dll )] internal extern static _flushall() : int; public static Main() : void { _ = puts( Test ); _ = _flushall(); } }

=External links=

*[http://nemerle.org/ Language Homepage] *[http://nemerle.org/Documentation#Language_documentation The official documentation]

*[http://www.99-bottles-of-beer.net/language-nemerle-869.html Nemerle at 99 Bottles of Beer] *[http://d.hatena.ne.jp/akiramei/searchdiaryword=%2a%5bNemerle%5d Interesting entries about Nemerle from akiramei s diary (in Japanese)]