Suvarna Garge (Editor)

Nemerle

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Developer
  
JetBrains

Paradigm
  
multi-paradigm: metaprogramming, functional, object-oriented, imperative

Designed by
  
Kamil Skalski, Michał Moskal, Prof. Leszek Pacholski, Paweł Olszta at Wrocław University

First appeared
  
2003; 14 years ago (2003)

Stable release
  
1.2.507.0 / 6 August 2016; 7 months ago (2016-08-06)

Typing discipline
  
static, strong, inferred, nominal

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 (OO) 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 is focusing on developing Nitra, a framework to implement extant and new programming languages. This framework will likely be used to create future versions of Nemerle.

Contents

Nemerle is named after the Archmage Nemmerle, a character in the fantasy novel A Wizard of Earthsea by Ursula K. Le Guin.

Features

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:

  • strong type inference
  • a flexible metaprogramming subsystem (using macros)
  • full support for object-oriented programming (OOP), in the style of C#, Java, and C++
  • full support for functional programming, in the style of ML, OCaml, and Haskell, with these features:
  • higher-order functions
  • pattern matching
  • algebraic types
  • local functions
  • tuples and anonymous types
  • partial application of functions
  • 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#.

    Variants

    Variants (called data types or sum types in SML and OCaml) are forms of expressing data of several different kinds:

    Metaprogramming

    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:

    IDE

    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 (like Visual Studio Express Editions) and SharpDevelop (link to plugin source code).

    Nemerle can be also integrated into Visual Studio 2010 using an add-in.

    Hello, World!

    The traditional Hello World! can be implemented in a more C#-like fashion:

    or more simply:

    Examples of macros

    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.

    String formatting

    The string formatting macro simplifies variables to string manipulations using $ notation:

    Declarative code generation

    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.

    Database accessibility

    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.

    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:

    ...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#'s and other .NET languages. Here is the simplest example:

    References

    Nemerle Wikipedia