Nemerle | |
Paradigm: | Multi-paradigm aspect-oriented, event-driven, functional, generic, imperative, meta, object-oriented, reflective |
Family: | C# |
Designers: | Kamil Skalski, Michał Moskal, Prof. Leszek Pacholski, Paweł Olszta at Wrocław University |
Developer: | JetBrains (formerly) RSDN |
Latest Release Version: | 1.2.507.0[1] |
Typing: | Inferred, nominal, static, strong |
Implementations: | Nemerle |
Influenced By: | C#, Lisp, ML |
Platform: | CLI |
File Ext: | .n |
Nemerle is a general-purpose, high-level, statically typed programming language designed for platforms using the Common Language Infrastructure (.NET/Mono). It offers functional, object-oriented, aspect-oriented, reflective and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system.
In June 2012, the core developers of Nemerle were hired by the Czech software development company JetBrains. The team was focusing on developing Nitra, a framework to implement extant and new programming languages.[2] [3] [4] Both the Nemerle language and Nitra have seemingly been abandoned or discontinued by JetBrains; Nitra has not been updated by its original creators since 2017 and Nemerle is now maintained entirely by the Russian Software Development Network, independently from JetBrains, although no major updates have been released yet and development is progressing very slowly. Neither Nemerle, nor Nitra have been mentioned or referenced by JetBrains for years.
Nemerle is named after the Archmage Nemmerle, a character in the fantasy novel A Wizard of Earthsea by Ursula K. Le Guin.
Nemerle's most notable feature is the ability to mix styles of programming that are object-oriented and functional. Programs may be structured using object-oriented concepts such as classes and namespaces, while methods can (optionally) be written in a functional style. Other notable features include:
The metaprogramming system allows for great compiler extensibility, embedding domain-specific languages, partial evaluation, and aspect-oriented programming, taking a high-level approach to lift as much of the burden as possible from programmers. The language combines all Common Language Infrastructure (CLI) standard features, including parametric polymorphism, lambdas, extension methods etc. Accessing the libraries included in the .NET or Mono platforms is as easy as in C#.
def x = if (DateTime.Now.DayOfWeek
def x = try int.Parse(someString) catch ;
def x = returnBlock : ;
def mult(x, y) ;
def fibonacci(i)
WriteLine(next(9)); // 10 similar to "Console.WriteLine(next(9));" WriteLine(mult(2, 2)); // 4WriteLine(fibonacci(10)); // 55
Variants (called data types or sum types in SML and OCaml) are forms of expressing data of several different kinds:
Nemerle's macro system allows for creating, analysing, and modifying program code during compiling. Macros can be used in the form of a method call or as a new language construct. Many constructs within the language are implemented using macros (if, for, foreach, while, using etc.).
"if" macro example:
// using this macro in code:def max = if (a > b) a else b;// during a compile time the upper line will be transformed to this:def max = match (a > b)
Similarly to the braceless syntax later added to Scala, Nemerle allows the programmer to optionally use a whitespace-sensitive syntax based on the off-side rule, similarly to Python.
The following curly-brace snippet:
[Qux]class FooBar
could be rewritten as:
[Qux] \class FooBar public static Main: void WriteLine("Hello")
static Foo (x: int): void if (x
static Bar: int def foo = 2 + 7 * 13 foo
Notably, it is not possible to break expressions or alternative clauses in matches over multiple lines without using a backslash \
:
// This will not compile ...
static Bar: int def foo = 2 + 7 * 13 foo
match (s) | "a" | "aa" => 1 | "b" | "bb" => 2 | _ => 0 // But this will:
static Bar: int def foo = 2 \ + 7 \ * 13 foo
match (s) | "a" \ | "aa" => 1 | "b" \ | "bb" => 2 | _ => 0
In order to activate this syntax, the user must add #pragma indent
to the top of the file or use the compiler option -i
.
Nemerle can be integrated into the integrated development environment (IDE) Visual Studio 2008. It also has a fully free IDE based on Visual Studio 2008 Shell[5] (like Visual Studio Express Editions) and SharpDevelop (link to plugin source code).
Nemerle can be also integrated into Visual Studio (up until 2017) using add-ins and extensions.[6]
The traditional Hello World! can be implemented in a more C#-like fashion:
or more simply:
Macros allow generating boilerplate code with added static checks performed by the compiler. They reduce the amount of code that must be written by hand, make code generation safer, and allow programs to generate code with compiler checks, while keeping source code relatively small and readable.
The string formatting macro simplifies variables to string manipulations using $ notation:
StructuralEquality, Memoize, json, and with are macros which generate code in compile time. Though some of them (StructuralEquality, Memoize) can look like C# attributes, during compiling, they will be examined by the compiler and transformed to appropriate code using logic predefined by their macros.
Using Nemerle macros for SQL you can write:
instead of
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.
With Nemerle macros you can also introduce some new syntax into the language:
defines a macro introducing the syntax and can be used like
ford (i ; n) print (i);
Nemerle can be either embedded directly into ASP.NET:
Page_Load(_ : object, _ : EventArgs) : void
EnterBtn_Click(_ : object, _ : EventArgs) : void
...Or stored in a separate file and entered with a single line:
Nemerle can take advantage of native platform libraries. The syntax is very similar to C#'s and other .NET languages. Here is the simplest example:
class PlatformInvokeTest