Nim (programming language) - Biblioteka.sk

Upozornenie: Prezeranie týchto stránok je určené len pre návštevníkov nad 18 rokov!
Zásady ochrany osobných údajov.
Používaním tohto webu súhlasíte s uchovávaním cookies, ktoré slúžia na poskytovanie služieb, nastavenie reklám a analýzu návštevnosti. OK, súhlasím


Panta Rhei Doprava Zadarmo
...
...


A | B | C | D | E | F | G | H | CH | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Nim (programming language)
 ...

Nim
The Nim crown logo
ParadigmsMulti-paradigm: compiled, concurrent, procedural, imperative, functional, object-oriented, meta
Designed byAndreas Rumpf
DeveloperNim Lang Team[1]
First appeared2008; 16 years ago (2008)
Stable release
2.0.4[2] Edit this on Wikidata / 16 April 2024; 37 days ago (16 April 2024)
Typing disciplineStatic,[3] strong,[4] inferred, structural
ScopeLexical
Implementation languageNim (self-hosted)
PlatformIA-32, x86-64, ARM, Aarch64, RISC-V, PowerPC ...[5]
OSCross-platform[6]
LicenseMIT License[7] Edit this on Wikidata
Filename extensions.nim, .nims, .nimble
Websitenim-lang.org
Influenced by
Ada, Modula-3, Lisp, C++, Object Pascal, Python, Oberon, Rust, ParaSail[8]

Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level systems programming language,[9] designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant",[10] supporting metaprogramming, functional, message passing,[11] procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.

Description

Nim is statically typed.[12] It supports compile-time metaprogramming features such as syntactic macros and term rewriting macros.[13] 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.[14] Iterators are supported and can be used as first class entities,[13] 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.[13] 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.[15]

... presents a most original design that straddles Pascal and Python and compiles to C code or JavaScript.[16]

— Andrew Binstock, editor-in-chief of Dr. Dobb's Journal, 2014

As of August 2023, Nim compiles to C, C++, JavaScript, Objective-C,[17] and LLVM.[18]

History

Branch Version Release date[19]
0.x Old version, no longer maintained: 0.10.2 2014-12-29
Old version, no longer maintained: 0.11.2 2015-05-04
Old version, no longer maintained: 0.12.0 2015-10-27
Old version, no longer maintained: 0.13.0 2016-01-18
Old version, no longer maintained: 0.14.2 2016-06-09
Old version, no longer maintained: 0.15.2 2016-10-23
Old version, no longer maintained: 0.16.0 2017-01-08
Old version, no longer maintained: 0.17.2 2017-09-07
Old version, no longer maintained: 0.18.0 2018-03-01
Old version, no longer maintained: 0.19.6 2019-05-13
Old version, no longer maintained: 0.20.2 2019-06-17
1.0 Old version, no longer maintained: 1.0.0 2019-09-23
Old version, no longer maintained: 1.0.10 2020-10-27
1.2 Old version, no longer maintained: 1.2.0 2020-04-03
Old version, no longer maintained: 1.2.18 2022-02-09
1.4 Old version, no longer maintained: 1.4.0 2020-10-16
Old version, no longer maintained: 1.4.8 2021-05-25
1.6 Old version, no longer maintained: 1.6.0 2021-10-19
Older version, yet still maintained: 1.6.20 2024-04-16
2.0 Old version, no longer maintained: 2.0.0 2023-08-01
Current stable version: 2.0.4 2024-04-16
Legend:
Old version
Older version, still maintained
Latest version
Latest preview version
Future release
For each 0.x branch, only the latest point release is listed.
For later branches, the first and the latest point release is listed.

Nim's initial development was started in 2005 by Andreas Rumpf. It was originally named Nimrod when the project was made public in 2008.[20]: 4–11 

The first version of the Nim compiler was written in Pascal using the Free Pascal compiler.[21] In 2008, a version of the compiler written in Nim was released.[22] The compiler is free and open-source software, and is being developed by a community of volunteers working with Andreas Rumpf.[23] The language was officially renamed from Nimrod to Nim with the release of version 0.10.2 in December 2014.[24] On September 23, 2019, version 1.0 of Nim was released, signifying the maturing of the language and its toolchain. On August 1st, 2023, version 2.0 of Nim was released, signifying the completion, stabilization of, and switch to the ARC/ORC memory model.[25]

Language design

Syntax

The syntax of Nim resembles that of Python.[26] 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

# Let's declare a function that takes any type of number and displays its double
# In Nim functions with side effect are called "proc"
proc timesTwo(i: SomeNumber) =
  echo i * 2
# Let's write another function that takes any ordinal type, and returns
# the double of the input in its original type, if it is a number;
# or returns the input itself otherwise.
# We use a generic Type(T), and precise that it can only be an Ordinal
func twiceIfIsNumber(i: T): T =
  when T is SomeNumber: # A `when` is an `if` evaluated during compile time
    result = i * 2 # You can also write `return i * 2`
  else:
    # If the Ordinal is not a number it is converted to int,
    # multiplied by two, and reconverted to its based type
    result = (i.int * 2).T
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.[27]

Nim was influenced by specific characteristics of existing languages, including the following:

Uniform Function Call Syntax

Nim supports Uniform Function Call Syntax (UFCS)[28] 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:

echo "hello world"
echo("hello world")
"hello world".echo()
"hello world".echo
echo("hello", " world")
"hello".echo(" world")
"hello".echo " world"

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.[29]

const useHttps = true
assert useHttps == useHttps
assert useHTTPS == useHttps
assert use_https == useHttps

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.[30]

type Type = object
  `int`: int

let `object` = Type(`int`: 9)
assert `object` is Type
assert `object`.`int` == 9

var `var` = 42
let `let` = 8
assert `var` + `let` == 50

const `assert` = true
assert `assert`

Compiler

The Nim compiler emits fast, optimized C code by default. It defers compiling-to-object code to an external C compiler[31] to leverage existing compiler optimization and portability. Many C compilers are supported, including Clang, Microsoft Visual C++ (MSVC), MinGW, and GNU Compiler Collection (GCC). The Nim compiler can also emit C++, Objective-C, and JavaScript code to allow easy interfacing with application programming interfaces (APIs) written in those languages;[9] developers can simply write in Nim, then compile to any supported language. This also allows writing applications for iOS and Android. There is also an unofficial LLVM backend, allowing use of the Nim compiler in a stand-alone way.[18]

The Nim compiler is self-hosting, meaning it is written in the Nim language.[32] The compiler supports cross-compiling, so it is able to compile software for any of the supported operating systems, no matter the development machine. This is useful for compiling applications for embedded systems, and for uncommon and obscure computer architectures.[citation needed]

Compiler options

By default, the Nim compiler creates a debug build.[33] With the option -d:release a release build can be created, which is optimized for speed and contains fewer runtime checks.[33] With the option -d:danger all runtime checks can be disabled, if maximum speed is desired.[33]

Memory management

Nim supports multiple memory management strategies, including the following:[34]

  • --gc:refc – Standard deferred reference counting based garbage collector with a simple mark-and-sweep backup GC in order to collect cycles. Heaps are thread-local.
  • --gc:markAndSweep – Simple mark-and-sweep based garbage collector. Heaps are thread-local.
  • --gc:boehmBoehm based garbage collector, it offers a shared heap.
  • --gc:goGo's garbage collector, useful for interoperability with Go. Offers a shared heap.
  • --gc:arc – Automatic reference counting (ARC) with move semantics optimizations, offers a shared heap. It offers fully deterministic performance for hard realtime systems.[35] Reference cycles may cause memory leaks: these may be dealt with by manually annotating {.acyclic.} pragmas or by using --gc:orc.
  • --gc:orc – Same as --gc:arc but adds a cycle collector (the "O") based on "trial deletion".[36] The cycle collector only analyzes types if they are potentially cyclic.
  • --gc:none – No memory management strategy nor a garbage collector. Allocated memory is simply never freed, unless manually freed by the developer's code.

As of Nim 2.0, ORC is the default GC.[37]

Development tools

Bundled

Many tools are bundled with the Nim install package, including:

Nimble

Nimble is the standard package manager used by Nim to package Nim modules.[38] It was initially developed by Dominik Picheta, who is also a core Nim developer. Nimble has been included as Nim's official package manager since Oct 27, 2015, the v0.12.0 release.[39]

Nimble packages are defined by .nimble files, which contain information about the package version, author, license, description, dependencies, and more.[20]: 132  These files support a limited subset of the Nim syntax called NimScript, with the main limitation being the access to the FFI. These scripts allow changing of test procedure, or for custom tasks to be written.

The list of packages is stored in a JavaScript Object Notation (JSON) file which is freely accessible in the nim-lang/packages repository on GitHub. This JSON file provides Nimble with a mapping between the names of packages and their Git or Mercurial repository URLs.

Nimble comes with the Nim compiler. Thus, it is possible to test the Nimble environment by running: nimble -v. This command will reveal the version number, compiling date and time, and Git hash of nimble. Nimble uses the Git package, which must be available for Nimble to function properly. The Nimble command-line is used as an interface for installing, removing (uninstalling), and upgrading–patching module packages.[20]: 130–131 

c2nim

c2nim is a source-to-source compiler (transcompiler or transpiler) meant to be used on C/C++ headers to help generate new Nim bindings.[40] The output is human-readable Nim code that is meant to be edited by hand after the translation process.

koch

koch is a maintenance script that is used to build Nim, and provide HTML documentation.[41]

nimgrep

Zdroj:https://en.wikipedia.org?pojem=Nim_(programming_language)
Text je dostupný za podmienok Creative Commons Attribution/Share-Alike License 3.0 Unported; prípadne za ďalších podmienok. Podrobnejšie informácie nájdete na stránke Podmienky použitia.






Text je dostupný za podmienok Creative Commons Attribution/Share-Alike License 3.0 Unported; prípadne za ďalších podmienok.
Podrobnejšie informácie nájdete na stránke Podmienky použitia.

Your browser doesn’t support the object tag.

www.astronomia.sk | www.biologia.sk | www.botanika.sk | www.dejiny.sk | www.economy.sk | www.elektrotechnika.sk | www.estetika.sk | www.farmakologia.sk | www.filozofia.sk | Fyzika | www.futurologia.sk | www.genetika.sk | www.chemia.sk | www.lingvistika.sk | www.politologia.sk | www.psychologia.sk | www.sexuologia.sk | www.sociologia.sk | www.veda.sk I www.zoologia.sk