This article may meet Wikipedia's criteria for speedy deletion as a page that was previously deleted via a deletion discussion, is substantially identical to the deleted version, and any changes do not address the reasons for which the material was deleted. See the previous discussion. See CSD G4.
If this article does not meet the criteria for speedy deletion, or you intend to fix it, please remove this notice, but do not remove this notice from pages that you have created yourself. If you created this page and you disagree with the given reason for deletion, you can click the button below and leave a message explaining why you believe it should not be deleted. You can also visit the talk page to check if you have received a response to your message. Note that this article may be deleted at any time if it unquestionably meets the speedy deletion criteria, or if an explanation posted to the talk page is found to be insufficient.
Note to administrators: this article has content on its talk page which should be checked before deletion. Note: Previously PROD-deleted or speedily deleted articles are not eligible under this criterion, although they may be deletable under other criteria. Check the deletion log for prior deletion rationales.Administrators: check links, talk, history (last), and logs before deletion. Consider checking Google. This page was last edited by Msnicki (contribs | logs) at 19:01, 25 March 2015 (UTC) (10 years ago) |
Nim (formerly known as Nimrod) is an imperative, multi-paradigm, compiled programming language[6] designed and developed by Andreas Rumpf. It is designed to be an "efficient, expressive, and elegant" programming language,[7] supporting metaprogramming,[8] functional, message passing,[9] procedural, and object-oriented programming styles.
Nim | |
---|---|
Paradigm | compiled, concurrent, procedural, imperative, object-oriented |
Designed by | Andreas Rumpf |
First appeared | 2008 |
Preview release | 0.10.2[1]
/ 2014-12-29 |
Typing discipline | static,[2] strong,[3] inferred, structural |
OS | Linux, Mac OS X, Windows, FreeBSD, NetBSD |
License | MIT License[4][5] |
Website | nim-lang |
Influenced by | |
Ada, Modula 3, Lisp, C++, Object Pascal, Python |
The Nim compiler was initially written in Pascal,[10] in 2008[1] a version of the compiler written in Nim was released. The compiler is open source and is being developed by a group of volunteers in addition to Andreas Rumpf.[11] The compiler generates optimized C code and defers compilation to an external compiler[12] (a large range of compilers including clang and GCC are supported) to leverage their optimization and portability capabilities. The compiler can also generate C++ and Objective C code to allow for easy interfacing with APIs written in those languages,[6] this in turn allows Nim to be used to write iOS as well as Android applications[13][14]
Description
Nim's syntax is an unusual blend between Python and Pascal.[15] The language shares many syntactical similarities to Python[16] (for example the if
and for
statements are practically identical), Nim however differs greatly when it comes to semantics: for a start Nim is statically typed.
Nim supports compile-time metaprogramming features such as AST macros and term rewriting macros,[17] the combination of these features is largely unique to Nim.[18] Term rewriting macros enable library implementations of common data structures such as bignums and matrixes to be implemented with an efficiency as if they would have been builtin language facilities. Iterators are supported and can be used as first class entities[17] in the language as can functions, these features allow for functional programming to be used. Object oriented programming is supported by inheritance and multiple dispatch. Functions can be generic and can also be overloaded, generics are further enhanced by the support for type classes. Operator overloading is also supported.[17]
Examples
The following code examples are valid as of Nim 0.10.2. Syntax and semantics may change in subsequent versions.
echo "Hello World!"
Reversing a string
proc reverse(s: string): string =
result = "" # implicit result variable
for i in countdown(high(s), 0):
result.add s[i]
var str1 = "Reverse This!"
echo "Reversed: ", reverse(str1)
This example shows many of Nim's features, one of the most exotic ones is the implicit result
variable: every procedure in Nim with a non-void return type has an implicit result variable that represents the value that will be returned. In the for loop we see an invocation of countdown
which is an iterator, if an iterator is omitted then the compiler will attempt to use an items
iterator if one is defined for the type that was specified in the for loop.
Metaprogramming
template genType(name, fieldname: expr, fieldtype: typedesc) =
type
name = object
fieldname: fieldtype
genType(Test, foo, int)
var x = Test(foo: 4566)
echo(x.foo) # 4566
This is an example of metaprogramming in Nim using its template facilities. The genType
is invoked at compile-time and a Test
type is created.
Wrapping C functions
proc printf(formatstr: cstring)
{.header: "<stdio.h>", varargs.}
printf("%s %d\n", "foo", 5)
Existing C code can directly be used in Nim. In this code the well known printf
function is imported into Nim and subsequently used.[19]
References
- ^ a b "News". Official website. Retrieved 2015-01-02.
- ^ "Nim by example". GitHub. Retrieved 2014-07-20.
- ^ Караджов, Захари; Станимиров, Борислав (2014). Метапрограмиране с Nimrod. VarnaConf (in Bulgarian). Retrieved 2014-07-27.
{{cite conference}}
: External link in
(help); Unknown parameter|conferenceurl=
|conferenceurl=
ignored (|conference-url=
suggested) (help) - ^ "FAQ". Official website. Retrieved 2014-07-20.
- ^ "copying.txt". Nim. GitHub. Retrieved 2014-07-20.
- ^ a b Rumpf, Andreas (2014-02-11). "Nimrod: A new systems programming language". Dr. Dobb's Journal. Retrieved 2014-07-20.
- ^ "The Nim Programming Language". Official website. Retrieved 2014-07-20.
- ^ "Nim Programming Language Gaining Traction". Slashdot anonymous poster. Retrieved 15 Feb 2014.
- ^ "FAQ". Official website. Retrieved 2013-04-05.
- ^ "Nim Pascal Sources". Nim. GitHub. Retrieved 2013-04-05.
- ^ "Contributors". Nim. GitHub. Retrieved 2013-04-05.
- ^ Rumpf, Andreas (2014-01-15). Nimrod: A New Approach to Metaprogramming. InfoQ. Event occurs at 2:23. Retrieved 2014-07-20.
- ^ Hankiewicz, Grzegorz Adam (2014-03-10). "Nimrod for cross platform software". Rants from the Ballmer Peak. GitHub. Retrieved 2014-07-20.
- ^ "Nimrod-on-android failure". 2012-07-28. Retrieved 2015-02-28.
- ^ Binstock, Andrew (2014-01-07). "The Rise And Fall of Languages in 2013". Dr. Dobb's.
- ^ Picheta, Dominik (2013-10-27). "About Nimrod's features". Blog. Retrieved 2014-07-20.
- ^ a b c "Nim Manual". Official website. Retrieved 2014-07-20.
- ^ Araq (2012-09-10). "Term rewriting macros". Nim Forum. Retrieved 2014-07-20.
- ^ "What is special about Nim?". HookRace. 2015-01-01. Retrieved 2015-02-17.