Nim is a general-purpose, multi-paradigm, statically typed, compiled, high-level system programming language. It was designed and developed by a team led by Andreas Rumpf. Nim aims to be "efficient, expressive, and elegant", and supports metaprogramming, functional, message passing, procedural, and object-oriented programming paradigms. Nim includes features such as compile-time code generation, algebraic data types, and a foreign function interface (FFI) for interfacing with C, C++, Objective-C, and JavaScript. It also supports compilation to these same languages as intermediate representations.
Description Nim is statically typed. It supports compile-time metaprogramming features such as syntactic macros and term rewriting macros. Term rewriting macros enable library implementations of common data structures, such as bignums and matrices, to be implemented efficiently and with syntactic integration, as if they were built-in language facilities. Iterators are supported and can be used as first class entities, as can functions, allowing for the use of functional programming methods. Object-oriented programming is supported by inheritance and multiple dispatch. Functions can be generic and overloaded, and generics are further enhanced by Nim's support for type classes. Operator overloading is also supported. Nim includes multiple tunable memory management strategies, including tracing garbage collection, reference counting, and fully manual systems, with the default being deterministic reference counting with optimizations via move semantics and cycle collection via trial deletion.[Nim] ... presents a most original design that straddles Pascal and Python and compiles to C code or JavaScript. As of August 2023, Nim compiles to C, C++, JavaScript, Objective-C, and LLVM.
History
Andreas Rumpf is the designer and original implementer of Nim. He received a diploma in computer science from the Technical University of Kaiserslautern, Germany. His research interests include hard real-time systems, embedded systems, compiler construction and artificial intelligence. Nim's initial development was started in 2005 under the name Nimrod and was made public in 2008. The first version of the Nim compiler was written in Pascal using the Free Pascal compiler. In 2008, a version of the compiler written in Nim was released. The compiler is free and open-source software, and is being developed by a community of volunteers working with Andreas Rumpf. The language was officially renamed from Nimrod to Nim with the release of version 0.10.2 in December 2014. On 23 September 2019, version 1.0 of Nim was released, signifying the maturing of the language and its toolchain. On 1 August 2023, version 2.0 of Nim was released, signifying the completion, stabilization of, and switch to the ARC/ORC memory model.
Language design
Syntax The syntax of Nim resembles that of Python. Code blocks and nesting statements are identified through use of whitespace, according to the offside-rule. Many keywords are identical to their Python equivalents, which are mostly English keywords, whereas other programming languages usually use punctuation. With the goal of improving upon its influence languages, even though Nim supports indentation-based syntax like Python, it introduced additional flexibility. For example, a single statement may span multiple lines if a comma or binary operator is at the end of each line. Nim also supports user-defined operators. Unlike Python, Nim implements (native) static typing. Nim's type system allows for easy type conversion, casting, and provides syntax for generic programming. Nim notably provides type classes which can stand in for multiple types, and provides several such type classes 'out of the box'. Type classes allow working with several types as if they were a single type. For example:
openarray – Represents arrays of different sizes, sequences, and strings SomeSignedInt – Represents all the signed integer types SomeInteger – Represents all the Integer types, signed or not SomeOrdinal – Represents all the basic countable and ordered types, except of non integer number This code sample demonstrates the use of typeclasses in Nim:
echo twiceIfIsNumber(67) # Passes an int to the function echo twiceIfIsNumber(67u8) # Passes an uint8 echo twiceIfIsNumber(true) # Passes a bool (Which is also an Ordinal)
Influence According to the language creator, Nim was conceived to combine the best parts of Ada typing system, Python flexibility, and powerful Lisp macro system. Nim was influenced by specific characteristics of existing languages, including the following:
Modula-3: traced vs untraced pointers Object Pascal: type safe bit sets (set of char), case statement syntax, various type names and filenames in the standard library Ada: subrange types, distinct type, safe variants – case objects C++: operator overloading, generic programming Python: Off-side rule Lisp: Macro system, AST manipulation, homoiconicity Oberon: export marker C#: async/await, lambda macros ParaSail: pointer-free programming
Uniform function call syntax Nim supports uniform function call syntax (UFCS) and identifier equality, which provides a large degree of flexibility in use. For example, each of these lines print "hello world", just with different syntax:
Identifier equality Nim is almost fully style-insensitive; two identifiers are considered equal if they only differ by capitalization and underscores, as long as the first characters are identical. This is to enable a mixture of styles across libraries: one user can write a library using snake_case as a convention, and it can be used by a different user in a camelCase style without issue.
Stropping The stropping feature allows the use of any name for variables or functions, even when the names are reserved words for keywords. An example of stropping is the ability to define a variable named if, without clashing with the keyword if. Nim's implementation of this is achieved via backticks, allowing any reserved word to be used as an identifier.
… excerpt ends here. Continue reading the full article.


