{{Article for deletion/dated|page=Nemerle|timestamp=20110205203949|year=2011|month=February|day=5|substed=yes|help=off}} {{Notability|date=April 2009}} {{expert-subject-multiple|.NET|Programming Languages|type=article|date=September 2009}} {{Infobox programming language |name = Nemerle |logo = |paradigm = [[multi-paradigm programming language|multi-paradigm]]: [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[imperative programming|imperative]] |year = |designer = [[Kamil Skalski]], [[Michał Moskal]], Prof. [[Leszek Pacholski]] and [[Paweł Olszta]] at [[Wrocław University]] |developer = |latest release version = 1.0.0 Beta 2 Update |latest release date = {{start date|2010|09|24}} |typing = [[static typing|static]], [[strong typing|strong]], [[inferred typing|inferred]] |implementations = Nemerle |dialects = |influenced_by = [[C Sharp (programming language)|C#]], [[ML (programming language)|ML]], [[Lisp (programming language)|Lisp]] |influenced = |platform = [[Common Language Runtime|CLR]] |website = http://nemerle.org/Main_Page}} '''Nemerle''' is a [[high level language|high-level]] [[static typing|statically typed]] [[programming language]] for the [[Microsoft .NET|.NET]] (see also [[Mono (software)|Mono]]) platform. It offers [[functional programming|functional]], [[object-oriented]] and [[imperative programming|imperative]] features. It has a simple [[C Sharp (programming language)|C#]]-like syntax and a powerful [[metaprogramming]] system. It has been named after the archmage Nemmerle from "[[A Wizard of Earthsea]]" by [[Ursula K. Le Guin]] (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]] 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 includes [[Delegates (programming)|functional values]], [[algebraic data types|variants]] and [[pattern matching]]. Another very important feature is taking a [[high level language|high-level]] approach in all aspects of the language—trying to lift as much of the burden from the programmer as possible. Features like [[metaprogramming|macros]] and [[type inference]] fit here. Features that come from the functional land are [[algebraic data types|variants]] (aka algebraic data types), [[pattern matching]], [[type inference]] and [[generic programming|parameter polymorphism]] (aka generics). The [[metaprogramming]] system allows great [[compiler]] extensibility, embedding [[domain specific languages]], [[partial evaluation]] and [[aspect oriented programming|aspect-oriented]] programming. Last but not least, the usage of more mundane library functionality from [[Microsoft .NET|.NET]] is as easy as in C#. ===Type inference=== def x = 1; // int def myList = List(); // generic List[T], type T is deduced from the usage in the next line myList.Add(x); // compiler deduces type of T as int making myList type of List[int] ===Everything is an expression=== def x = { // similar to x = 3 def y = 1; def z = 2; y + z // this last statement is a block return value } def x = if (DateTime.Now.DayOfWeek == DayOfWeek.Monday) // if, using, try are also expressions "Monday" else "other day"; def x = try { Int32.Parse(someString) } catch { | FormatException() => 0; } ===Tuples=== def k = (1, "one"); // k : (int * string) def (a, b) = k; // a = 1, b = "one" ===Pattern matching=== def result = match (number) { | 0 => "zero" | 1 => "one" | x when x < 0 => "negative" | _ => "more than one" } ===Functional types and local functions=== def next(x) { x + 1 }; def mult(x, y) { x * y } def fibbonacci(i) { | 0 => 0 | 1 => 1 | other => other + fibbonacci(i - 1) } Console.WriteLine(next(9)); // 10 Console.WriteLine(mult(2, 2)); // 4 Console.WriteLine(fibbonacci(10)); // 55 ===Metaprogramming=== Nemerle allows to create, analyze and modify code of a program during a compilation process using a powerfull macro system. Macros can be used in a form of a method call or even a new language construction. Most of the Nemerle language constructions are macros (if, for, foreach, while, using etc.). "if" macro example: macro @if (cond, e1, e2) syntax ("if", "(", cond, ")", e1, Optional (";"), "else", e2) { /* <[ ]> defines an area of quasi-quotation, the Nemerle compiler transforms a code in a such block to an AST tree, such transformations are somewhat similar to an Expression compiling in C# */ <[ match ($cond : bool) { | true => $e1 | _ => $e2 } ]> } // now we can use this macro in our code: def max = if (a > b) a else b; // during a compile time the upper line will be transformed to the following: def max = match (a > b) { | true => a | _ => b } == IDE == Nemerle can be integrated into [[Visual Studio 2008]]. Also it has a completely free IDE based on [[Visual Studio 2008|Visual Studio 2008 Shell]] (like [[Visual Studio Express Edition]]s) and [[SharpDevelop]] ([http://code.google.com/p/nemerle/source/browse/#svn%2Fnemerle%2Ftrunk%2Fsnippets%2Fsharpdevelop link to plugin source code]). ==Examples== ===Hello, World!=== The traditional [[Hello world program|"Hello World!"]] 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: $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 in a library, but additional work performed by the compiler to understand the query string, the variables used there, and the 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) { <[ for ($i = $begin; $i >= 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 Language="Nemerle" %>
Please enter your name:

...Or stored in a separate file and entered with a single line: <%@ Page Language="Nemerle" Src="test.n" Inherits="Test" %> ===PInvoke=== Nemerle can take advantage of native platform libraries. The syntax is very similar to C#'s and other [[Microsoft .NET|.NET]] languages. Here is the simplest example: 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://rsdn.ru/summary/3766.xml Publications about Nemerle in RSDN Magazine, russian official science magazine] *[http://research.microsoft.com/en-us/um/people/moskal/pdf/msc.pdf Type Inference with Deferral, Michał Moskal] *[http://research.microsoft.com/en-us/events/sscli2005/pacholski-moskal.pdf Nemerle presentation on Microsoft Research SSCLI RFP II Capstone 2005 workshop] *[http://nemerle.org/ Language Homepage] *[http://code.google.com/p/nemerle/ Project Hosting on Google Code] *[http://nemerle.org/Documentation#Language_documentation The official documentation] *[http://groups.google.com/group/nemerle-en Nemerle Forum] *[http://www.99-bottles-of-beer.net/language-nemerle-869.html Nemerle at 99 Bottles of Beer] *[http://d.hatena.ne.jp/akiramei/searchdiary?word=%2a%5bNemerle%5d Interesting entries about Nemerle from akiramei's diary (in Japanese)] ==Books about Nemerle== * {{cite book | editor1-last = Timpledon | editor1-first = Lambert M. | editor2-last = Markeseken | editor2-first = Miriam T. | editor3-last = Surhone | editor3-first = Susan F. | title = Nemerle | publisher = [[Betascript Publishing]] | year = 2010 | pages = 192 | isbn = 9786130909895 | url = http://search.barnesandnoble.com/Nemerle/Lambert-M-Surhone/e/9786130909895 | accessdate = 2011-02-11 }} The contents of this book are from Wikipedia and other free online sources. {{Cite web | title = Nemerle, Lambert M. Surhone, (9786130909895) Paperback - Barnes & Noble | publisher = [[Barnes & Noble]] | url = http://search.barnesandnoble.com/Nemerle/Lambert-M-Surhone/e/9786130909895 | accessdate = 2011-02-11 }} * {{cite book | editor = [[Books LLC]] | title = Ml Programming Language Family: Ml, Standard Ml, Objective Caml, Mythryl, F Sharp, Nemerle, Alice, Standard Ml of New Jersey, Concurrent Ml | publisher = [[Books LLC]] | year = 2010 | month = July | pages = 100 | isbn = 9781155461298 | url = http://search.barnesandnoble.com/Ml-Programming-Language-Family/Books-LLC/e/9781155461298 | accessdate = 2011-02-11 }} ==References== {{DotNET}} [[Category:Procedural programming languages]] [[Category:.NET programming languages]] [[Category:Object-oriented programming languages]] [[Category:ML programming language family]] [[Category:Programming languages created in 2003]] [[ja:Nemerle]] [[pl:Nemerle]] [[ru:Nemerle]] [[fi:Nemerle]] [[tg:Nemerle]] [[uk:Nemerle]] [[zh:Nemerle]]