Questions tagged [nim-lang]

Nim (formerly known as "Nimrod") is a statically typed, imperative programming language that tries to give the programmer ultimate power without compromises on runtime efficiency. This means it focuses on compile-time mechanisms in all their various forms.

About Nim

Beneath a nice infix/indentation based syntax with a powerful (AST based, hygienic) macro system lies a semantic model that supports a soft realtime GC on thread local heaps. Asynchronous message passing is used between threads, so no "stop the world" mechanism is necessary. An unsafe shared memory heap is also provided for the increased efficiency that results from that model.

Nim is efficient

  • Native code generation (currently via compilation to C), not dependent on a virtual machine: Nim produces small executables without dependencies for easy redistribution.
  • A fast non-tracing garbage collector that supports soft real-time systems (like games).
  • System programming features:

    • Ability to manage your own memory and access the hardware directly.
    • Pointers to garbage collected memory are distinguished from pointers to manually managed memory.
  • Zero-overhead iterators.
  • Cross-module inlining.
  • Dynamic method binding with inlining and without virtual method table. Compile time evaluation of user-defined functions.
  • Whole program dead code elimination: Only used functions are included in the executable.
  • Value-based datatypes: For instance, objects and arrays can be allocated on the stack.

Nim is expressive

  • The Nim compiler and all of the standard libraries are implemented in Nim.
  • Built-in high level datatypes: strings, sets, sequences, etc.
  • Modern type system with local type inference, tuples, variants, generics, etc.
  • User-defineable operators; code with new operators is often easier to read than code which overloads built-in operators. For example, a =~ operator is defined in the re module.
  • Macros can modify the abstract syntax tree at compile time.

Nim is elegant

  • Macros can use the imperative paradigm to construct parse trees. Nim does not require a different coding style for meta programming.
  • Macros cannot change Nim's syntax because there is no need for it. Nim's syntax is flexible enough.
  • Statements are grouped by indentation but can span multiple lines. Indentation must not contain tabulators so the compiler always sees the code the same way as you do.

Nim plays nice with others

  • The Nim Compiler runs on Windows, Linux, BSD and Mac OS X. Porting to other platforms is easy.
  • The Nim Compiler can also generate C++ or Objective C for easier interfacing.
  • There are lots of bindings: for example, bindings to GTK2, the Windows API, the POSIX API, OpenGL, SDL, Cairo, Python, Lua, TCL, X11, libzip, PCRE, libcurl, mySQL and SQLite are included in the standard distribution or can easily be obtained via the Nimble package manager.
  • A C to Nim conversion utility: New bindings to C libraries are easily generated by c2nim.

Official Resources

IDE

Tutorials

Discussions

652 questions
-2
votes
2 answers

How to make a HTTP request in Nim

How to make a HTTP request in Nim?
Alexandre Daubricourt
  • 3,323
  • 1
  • 34
  • 33
-2
votes
1 answer

Nim check if file exists

How to check if a file exists in Nim? A simple question that might be too long to look for in the official documentation! I wish someone would have asked that question here.
Alexandre Daubricourt
  • 3,323
  • 1
  • 34
  • 33
-2
votes
1 answer

For loops in nim

I would like to know how to make for loops in Nim. This is my code by far int i = 1 # for loop expected here Please help.
user14074696
-3
votes
2 answers

Compile C-code which was generated by Nim

I heard that if you run Nim to generate C-code: nim c -d: release try1.nim Then the further generated C code can be slipped into any compiler on any operating system. In the nimcache folder, the following is generated: @ mtry1.nim.c…
-3
votes
1 answer

How do I get input from the console in Nim?

I'm new to Nim, but it appears that there is no way to get input from the console in a similar way to input() in python or Console.ReadLine() in dotnet. I want execution of my code to pause, wait for input, then on pressing enter to continue (just…
Yellowsink
  • 129
  • 1
  • 10
-3
votes
1 answer

Internal error when declaring an empty table

Here's my code (I'm using Nim v1.2.0): var test_table = initTable[int, string]() When I compile I get a confusing error message that doesn't even refer to the line of code above: Error: internal error: genTypeInfo(tyNone) No stack traceback…
Jason
  • 531
  • 6
  • 19
1 2 3
43
44