Nim (programming language): Difference between revisions

Content deleted Content added
Yobot (talk | contribs)
m WP:CHECKWIKI error fixes using AWB (10823)
Dom96 (talk | contribs)
Restored from draft
Line 1:
{{other uses|Nim (disambiguation)}}
{{Infobox programming language
| name = Nim (formerly Nimrod)
|logo caption =
| paradigm = [[compiled language|compiled]], [[concurrent programming|concurrent]], [[procedural programming|procedural]], [[imperative programming|imperative]], [[object-oriented programming|object-oriented]]
|logo_size =
|paradigm year = {{start date and age|2008}}
|year designer = {{startAndreas date and age|df=yes|2014}}Rumpf
|designer developer = Andreas Rumpf
| latest_release_version =
|developer = Andreas Rumpf and Contributors
| latest_release_date =
| latest_release_version = 0.10.2<br>{{release date|df=yes|2014|12|29}}<ref>{{cite web |url=http://nim-lang.org/news.html#Z2014-12-29-version-0-10-2-released |title=Nim 0.10.2 |publisher=Andreas Rumpf and Contributors|accessdate=15 Feb 2014}}</ref>
| latest_test_version = 0.10.2<ref name="news">{{cite web|url=http://nim-lang.org/news.html|title=News|work=Official website|accessdate=2015-01-02}}</ref>
|typing = [[static typing|static]]
|implementations latest_test_date = 2014-12-29
| typing = [[static typing|static]]<ref name="nimbyex">{{cite web|url=http://nimrod-by-example.github.io/|title=Nimrod by example|publisher=[[Github]]|accessdate=2014-07-20}}</ref>, [[strong typing|strong]]<ref name="nimrodbg">{{cite conference|url=http://ibob.github.io/slides/nimrodbg/#/|language=Russian|title=Метапрограмиране с Nimrod|last1=Караджов|first1=Захари|last2=Станимиров |first2=Борислав|year=2014|conference=VarnaConf|conferenceurl=http://varnaconf.com/|accessdate=2014-07-27}}</ref>, [[type inference|inferred]], [[structural type system|structural]]
|dialects =
|logo_size dialects = =
|influenced_by = Python, Pascal<ref>{{cite web |url=http://developers.slashdot.org/story/15/02/15/0411217/nim-programming-language-gaining-traction?utm_source=slashdot&utm_medium=twitter |title=Nim Programming Language Gaining Traction |publisher=Slashdot anonymous poster|accessdate=15 Feb 2014}}</ref>
| influenced_by = [[Ada (programming language)|Ada]], [[Modula 3]], [[Lisp (programming language)|Lisp]], [[C++ (programming language)|C++]], [[Object Pascal]], [[Python (programming language)|Python]]
|influenced =
| operating_system = [[Cross-platformLinux]], [[Mac OS X]], [[Microsoft Windows|Windows]], [[FreeBSD]], [[NetBSD]]
| license = [[MIT License]]<ref name='license'>{{cite web|url=http://www.nimrod-lang.org/question.html|title=FAQ|work=Official website|accessdate = 2014-07-20}}</ref><ref name='license1'>{{cite web|url=https://github.com/Araq/Nimrod/blob/master/copying.txt|title=copying.txt|work=Nimrod|publisher=[[Github]]|accessdate=2014-07-20}}</ref>
|license = [[MIT License]]
| website = {{URL|http://www.nim-lang.org/}}
|file_ext = .nim
|wikibooks =
}}
'''Nim''' (formerly known as Nimrod) is an [[imperative programming|imperative]], [[multi-paradigm programming language|multi-paradigm]], [[compiled programming language]]<ref name="drdobbs">{{cite web|url=http://www.drdobbs.com/open-source/nimrod-a-new-systems-programming-languag/240165321|title=Nimrod: A new systems programming language|first=Andreas|last=Rumpf|work=[[Dr. Dobb's Journal]]|date=2014-02-11|accessdate=2014-07-20}}</ref> designed and developed by Andreas Rumpf. It is designed to be an "efficient, expressive, and elegant" programming language,<ref name="nimrod-lang">{{cite web|url=http://nim-lang.org/|title=The Nimrod Programming Language|work=Official website|accessdate=2014-07-20}}</ref> supporting [[metaprogramming]], [[functional programming|functional]], [[message passing]],<ref name="concurrency">{{cite web|url=http://www.nimrod-lang.org/question.html|title=FAQ|work=Official website|accessdate=2013-04-05}}</ref> [[Procedural programming|procedural]], and [[Object-oriented programming|object-oriented]] programming styles.
 
The Nim compiler was initially written in Pascal,<ref name="pas-sources">{{cite web|url=https://github.com/Araq/Nimrod/tree/ea1f1ec6d4d6c776eb0f81c2bebdd4cb4c817ebe/nim|title=Nimrod pascal sources|work=Nimrod|publisher=[[Github]]|accessdate=2013-04-05}}</ref> in 2008<ref name="news"/> 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.<ref name="contributors">{{cite web|url=https://github.com/Araq/Nimrod/contributors|title=Contributors|work=Nimrod|publisher=[[Github]]|accessdate=2013-04-05}}</ref> The compiler generates optimized C code and defers compilation to an external compiler<ref name="infoq">{{cite video|url=http://www.infoq.com/presentations/nimrod|title=Nimrod: A New Approach to Metaprogramming|first=Andreas|last=Rumpf|work=[[InfoQ]]|time=2:23|date=2014-01-15|accessdate=2014-07-20}}</ref> (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<ref name="drdobbs"/>, this in turn allows Nim to be used to write iOS as well as Android applications<ref name="gradhacrossplatform">{{cite web|url=http://gradha.github.io/articles/2014/03/nimrod-for-cross-platform-software.html|title=Nimrod for cross platform software|first=Grzegorz Adam|last=Hankiewicz|work=Rants from the Ballmer Peak|publisher=[[Github]]|date=2014-03-10|accessdate=2014-07-20}}</ref>
'''Nim''' is a programming language.<ref>{{cite web|url=http://nim-lang.org/|title=Nim Programming Language|accessdate=15 Feb 2015}}</ref> Prior to version 0.10, the language was referred to as Nimrod.<ref>{{cite web|url=http://goran.krampe.se/2014/10/15/bootstrapping-nim/|title=Bootstrapping Nim(rod)|last=Krampe|first=Göran|date=14 Oct 2014|accessdate=15 Feb 2015}}</ref> The language was developed by Andreas Rumpf.<ref>{{cite web|url=https://thestrangeloop.com/sessions/nimrod-a-new-approach-to-meta-programming|title=Nimrod: A new approach to meta programming|accessdate=15 Feb 2015}}</ref> Nim is statically typed.
 
==References Description ==
{{Reflist}}
 
Nim's syntax is an unusual blend between Python and Pascal<ref>{{Cite web|url = http://www.drdobbs.com/jvm/the-rise-and-fall-of-languages-in-2013/240165192|title = The Rise And Fall of Languages in 2013|date = 2014-01-07|accessdate = |website = |publisher = Dr. Dobb's|last = Binstock|first = Andrew}}</ref>. The language shares many syntactical similarities to Python<ref name="pichetablog">{{cite web|url=http://picheta.me/articles/2013/10/about-nimrods-features.html|title=About Nimrod's features|first=Dominik|last=Picheta|work=Blog|date=2013-10-27|accessdate=2014-07-20}}</ref> (for example the <code>if</code> and <code>for</code> statements are practically identical), Nim however differs greatly when it comes to semantics: for a start Nimr is statically typed.
[[Category:Statically typed programming languages]]
 
Nim supports compile-time metaprogramming features such as AST macros and term rewriting macros,<ref name="manual">{{cite web|url=http://nim-lang.org/manual.html|title=Nimrod Manual|work=Official website|accessdate=2014-07-20}}</ref> the combination of these features is largely unique to Nimrod.<ref name="trforum">{{cite web|url=http://forum.nimrod-lang.org/t/70|title=Term rewriting macros|last=Araq|work=Nimrod Forum|date=2012-09-10|accessdate=2014-07-20}}</ref> 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<ref name="manual"/> 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.<ref name="manual"/>
== Examples ==
 
The following code examples are valid as of Nim 0.9.4. Syntax and semantics may change in subsequent versions.
{{prog-lang-stub}}
 
=== [[Hello world]]<ref name="drdobbs" /> ===
 
<syntaxhighlight lang="python">
echo "Hello World!"
</syntaxhighlight>
 
=== Reversing a string ===
 
<syntaxhighlight lang="python">
proc reverse(s: string): string =
result = ""
for i in countdown(high(s), 0):
result.add s[i]
 
var str1 = "Reverse This!"
echo "Reversed: ", reverse(str1)
</syntaxhighlight>
This example shows many Nim features, one of the most exotic ones is the implicit <code>result</code> 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 <code>countdown</code> which is an iterator, if an iterator is omitted then the compiler will attempt to use an <code>items</code> iterator if one is defined for the type that was specified in the for loop.
 
=== Metaprogramming ===
 
<syntaxhighlight lang="python">
template GenType(name, fieldname: expr, fieldtype: typedesc) =
type
name = object
fieldname: fieldtype
 
GenType(TTest, foo, int)
 
var x = TTest(foo: 4566)
echo(x.foo) # 4566
</syntaxhighlight>
This an example of metaprogramming in Nim using its template facilities. The <code>GenType</code> is invoked at compile-time and a <code>TTest</code> type is created.
 
== References ==
 
{{reflist|30em}}
 
== External links ==
 
* {{official website|http://nim-lang.org/}}
* [https://github.com/Araq/Nim/wiki Nim Language Wiki]
* [http://forum.nim-lang.org Nim Forum]
* [https://github.com/Araq/Nim Primary source code repository and bug tracker]
* [http://rosettacode.org/wiki/Nim Nim code examples at Rosetta Code]
[[:Category:Systems programming languages]]
[[:Category:Concurrent programming languages]]
[[:Category:Statically typed programming languages]]
[[:Category:Multi-paradigm programming languages]]
[[:Category:Functional languages]]
[[:Category:Procedural programming languages]]