Nemerle
   HOME

TheInfoList



OR:

Nemerle is a general-purpose,
high-level High-level and low-level, as technical terms, are used to classify, describe and point to specific goals of a systematic operation; and are applied in a wide range of contexts, such as, for instance, in domains as widely varied as computer scienc ...
,
statically typed In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
designed for platforms using the
Common Language Infrastructure The Common Language Infrastructure (CLI) is an open specification and technical standard originally developed by Microsoft and standardized by ISO/IEC (ISO/IEC 23271) and Ecma International (ECMA 335) that describes executable code and a runt ...
( .NET/
Mono Mono may refer to: Common meanings * Infectious mononucleosis, "the kissing disease" * Monaural, monophonic sound reproduction, often shortened to mono * Mono-, a numerical prefix representing anything single Music Performers * Mono (Japanese b ...
). It offers
functional Functional may refer to: * Movements in architecture: ** Functionalism (architecture) ** Form follows function * Functional group, combination of atoms within molecules * Medical conditions without currently visible organic basis: ** Functional sy ...
,
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
,
aspect-oriented In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code (an advice) ''without'' modifying th ...
,
reflective Reflection is the change in direction of a wavefront at an interface between two different media so that the wavefront returns into the medium from which it originated. Common examples include the reflection of light, sound and water waves. The ' ...
and imperative features. It has a simple C#-like syntax and a powerful
metaprogramming Metaprogramming is a programming technique in which computer programs have the ability to treat other programs as their data. It means that a program can be designed to read, generate, analyze or transform other programs, and even modify itself ...
system. In June 2012, the core developers of Nemerle were hired by the
Czech Czech may refer to: * Anything from or related to the Czech Republic, a country in Europe ** Czech language ** Czechs, the people of the area ** Czech culture ** Czech cuisine * One of three mythical brothers, Lech, Czech, and Rus' Places *Czech, ...
software Software is a set of computer programs and associated documentation and data. This is in contrast to hardware, from which the system is built and which actually performs the work. At the lowest programming level, executable code consists ...
development company
JetBrains JetBrains s.r.o. (formerly IntelliJ Software s.r.o.) is a Czech software development company which makes tools for software developers and project managers. , the company has offices in Prague; Munich; Berlin; Boston, Massachusetts; Amsterda ...
. The team was focusing on developing Nitra, a framework to implement extant and new programming languages. 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 ''A Wizard of Earthsea'' is a fantasy novel written by American author Ursula K. Le Guin and first published by the small press Parnassus in 1968. It is regarded as a classic of children's literature and of fantasy, within which it is widely in ...
'' by
Ursula K. Le Guin Ursula Kroeber Le Guin (; October 21, 1929 – January 22, 2018) was an American author best known for her works of speculative fiction, including science fiction works set in her Hainish universe, and the '' Earthsea'' fantasy series. She was ...
.


Features

Nemerle's most notable feature is the ability to mix styles of programming that are
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
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 Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistics ...
* a flexible metaprogramming subsystem (using macros) * full support for
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
(OOP), in the style of C#,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, and
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
* full support for functional programming, in the style of ML,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
, and
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lang ...
, with these features: **
higher-order functions In mathematics and computer science, a higher-order function (HOF) is a function that does at least one of the following: * takes one or more functions as arguments (i.e. a procedural parameter, which is a parameter of a procedure that is itself ...
**
pattern matching In computer science, pattern matching is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact: "either it will or will not be ...
**
algebraic types In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite type, i.e., a type formed by combining other types. Two common classes of algebraic types are product types (i.e., ...
** local functions **
tuple In mathematics, a tuple is a finite ordered list (sequence) of elements. An -tuple is a sequence (or ordered list) of elements, where is a non-negative integer. There is only one 0-tuple, referred to as ''the empty tuple''. An -tuple is defi ...
s and
anonymous type Anonymous types are a feature of C# 3.0, Visual Basic .NET 9.0, Oxygene, Scala and Go that allows data types to encapsulate a set of properties into a single object without having to first explicitly define a type. This is an important feature ...
s **
partial application In computer science, partial application (or partial function application) refers to the process of fixing a number of arguments to a function, producing another function of smaller arity. Given a function f \colon (X \times Y \times Z) \to N , ...
of functions The metaprogramming system allows for great
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
extensibility, embedding
domain-specific language A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging f ...
s,
partial evaluation In computing, partial evaluation is a technique for several different types of program optimization by specialization. The most straightforward application is to produce new programs that run faster than the originals while being guaranteed to ...
, and
aspect-oriented programming In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code (an advice) ''without'' modifying t ...
, taking a
high-level High-level and low-level, as technical terms, are used to classify, describe and point to specific goals of a systematic operation; and are applied in a wide range of contexts, such as, for instance, in domains as widely varied as computer scienc ...
approach to lift as much of the burden as possible from programmers. The language combines all
Common Language Infrastructure The Common Language Infrastructure (CLI) is an open specification and technical standard originally developed by Microsoft and standardized by ISO/IEC (ISO/IEC 23271) and Ecma International (ECMA 335) that describes executable code and a runt ...
(CLI) standard features, including
parametric polymorphism In programming languages and type theory, parametric polymorphism allows a single piece of code to be given a "generic" type, using variables in place of actual types, and then instantiated with particular types as needed. Parametrically polymorph ...
, lambdas,
extension method In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-orie ...
s etc. Accessing the libraries included in the .NET or Mono platforms is as easy as in C#.


Type inference

def x = 1; // int def myList = List(); // generic List 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 nt


Everything is an expression

def x = ; def x = if (DateTime.Now.DayOfWeek

DayOfWeek.Monday) // if, using, try are also expressions "Monday" else "other day"; def x = try int.Parse(someString) catch ; def x = returnBlock : ;


Tuples

def k = (1, "one"); // k : (int * string) def (a, b) = k; // a = 1, b = "one"


Pattern matching

def result = match (number)


Functional types and local functions

using System.Console; // classes and modules (static classes) can be put in namespaces def next(x) ; // the type of x argument and other function arguments can be deduced from usage def mult(x, y) ; def fibonacci(i) ; WriteLine(next(9)); // 10 similar to "Console.WriteLine(next(9));" WriteLine(mult(2, 2)); // 4 WriteLine(fibonacci(10)); // 55


Variants

Variants Variant may refer to: In arts and entertainment * ''Variant'' (magazine), a former British cultural magazine * Variant cover, an issue of comic books with varying cover art * ''Variant'' (novel), a novel by Robison Wells * " The Variant", 2021 e ...
(called data types or sum types in SML and OCaml) are forms of expressing data of several different kinds: variant RgbColor


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: macro @if (cond, e1, e2) syntax ("if", "(", cond, ")", e1, Optional (";"), "else", e2) // 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)


Braceless syntax

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 A computer programming language is said to adhere to the off-side rule of syntax if blocks in that language are expressed by their indentation. The term was coined by Peter Landin, possibly as a pun on the offside rule in association football. ...
, similarly to
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
. The following curly-brace snippet: using System.Console; uxclass FooBar could be rewritten as: using System.Console; ux\ class FooBar public static Main(): void WriteLine("Hello") static Foo (x: int): void if (x

3) def y = x * 42; Foo (x) else Map (fun (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.


IDE

Nemerle can be integrated into the
integrated development environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools a ...
(IDE)
Visual Studio 2008 Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including web site, websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platfor ...
. It also has a fully free IDE based on Visual Studio 2008 Shell (like
Visual Studio Express Edition Microsoft Visual Studio Express is a set of integrated development environments (IDEs) that Microsoft developed and released free of charge. They are function-limited version of the non-free Visual Studio and require mandatory registration. Exp ...
s) and
SharpDevelop SharpDevelop (also styled as #develop) is a discontinued free and open source integrated development environment (IDE) for the .NET Framework, Mono, Gtk# and Glade# platforms. It supports development in C#, Visual Basic .NET, Boo, F#, IronPyt ...

link to plugin source code
. Nemerle can be also integrated into
Visual Studio Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including web site, websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platfor ...
(up until 2017) using add-ins and extensions.Visual Studio 2010 add-in
/ref>


Examples


Hello, World!

The traditional '' Hello World!'' can be implemented in a more C#-like fashion: class Hello or more simply: System.Console.WriteLine("Hello, world!");


Examples of macros

Macros allow generating
boilerplate code In computer programming, boilerplate code, or simply boilerplate, are sections of code that are repeated in multiple places with little to no variation. When using languages that are considered ''verbose'', the programmer must write a lot of boile ...
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: def s = $"The number is $i"; //insert the value of the variable i where $i is placed def s = $"$x + $y = $(x+y)"; // $(...) can be used to make calculations or access members


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. tructuralEquality// Implement IEquatable
ample In mathematics, a distinctive feature of algebraic geometry is that some line bundles on a projective variety can be considered "positive", while others are "negative" (or a mixture of the two). The most important notion of positivity is that of a ...
.Net interface using by element comparison equality. class Sample


Database accessibility

Using Nemerle macros for SQL you can write: ExecuteReaderLoop("SELECT firstname, lastname FROM employee WHERE firstname = $myparm", dbcon, ); instead of string sql = "SELECT firstname, lastname FROM employee WHERE firstname = :a"; using (NpgsqlCommand dbcmd = new NpgsqlCommand (sql, dbcon, dbtran)) 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) defines a macro introducing the syntax and can be used like ford (i ; n) print (i);


Nemerle with ASP.NET

Nemerle can be either embedded directly into
ASP.NET ASP.NET is an open-source, server-side web-application framework designed for web development to produce dynamic web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, applications and services. The name s ...
: <%@ 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 .NET languages. Here is the simplest example: using System; using System.Runtime.InteropServices; class PlatformInvokeTest


References


Further reading


Publications about Nemerle in RSDN Magazine, Russian official science magazine
*
Presentation "Nemerle is notable" by Denis Rystsov

Article "Unconventional languages for unconventional supercomputers" by Andrey Adinetz


External links

*
GitHub project and repository (new development)Google Code project and repository (old development)Nemerle ForumNemerle presentation on Microsoft Research SSCLI RFP II Capstone 2005 workshop
{{DEFAULTSORT:Nemerle Programming languages Procedural programming languages .NET programming languages Object-oriented programming languages Programming languages created in 2003 2003 software High-level programming languages Aspect-oriented programming Functional languages