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
0
votes
1 answer

Join array in nim

I'm not entirely sure why, but I can't figure out how to join an array in Nim, here's the code: import std/strformat proc check(to: int, multi: int, toreturn: string): string = if to mod multi == 0: return toreturn else: return…
0
votes
1 answer

Nim source file which after it's normalized

How is the Nim capability to be able to produce its source file which has all been normalized, i.e. evaluated/expanded all of the directives, templates, macros, etc.with their same arguments ?
itil memek cantik
  • 1,167
  • 2
  • 11
0
votes
2 answers

How do I create a mutable reference to an object in another object?

When I try to create two objects, where the second object has a reference to the first, I get Error: invalid type: 'var Foo' in this context: 'Bar' for var: type Foo = object x: int type Bar = object foo: var Foo var f = Foo(x:…
congusbongus
  • 13,359
  • 7
  • 71
  • 99
0
votes
1 answer

Must have Nim function default argument as a mutable variable

How do we have Nim function default parameter/argument for mutable ( r/w ) argument the simplest i.e. usually in boolean? e.g. illustration: proc foo( m:int; n :var int) = # <- how the correct one if n : echo 7+m+n else : echo m foo 7…
itil memek cantik
  • 1,167
  • 2
  • 11
0
votes
1 answer

To reset Nim runtime array

How to reset e.g. var d= newSeqOfCap[ int ](70) after so many pushes ie. d.add( ), to be as if the first empty, not ever have been pushed ?
itil memek cantik
  • 1,167
  • 2
  • 11
0
votes
1 answer

Nim is to assign variable in or beside other expression once

How Nim's way assign variable in or beside other expression at once, the one that'd always led to: Error: expression 's = "foo"' has no type (or is ambiguous) when trying like c/c++ code if (s = "foo").len > 5 { cout<< "Yes" ;} or some else? the…
itil memek cantik
  • 1,167
  • 2
  • 11
0
votes
2 answers

How to disable warning in Nim

I'm trying to suppress this warning: Warning: inherit from a more precise exception type like ValueError, IOError or OSError. If these don't suit, inherit from CatchableError or Defect. [InheritFromException] And I tried this: type …
pooooky
  • 490
  • 2
  • 12
0
votes
1 answer

Nim Table is not updated

I'm pretty new to Nim. I have this code: type Environment* = object values*: Table[string, BaseType] error*: Error proc newEnv*(errorObj: Error): Environment = return Environment( values: initTable[string, BaseType](), error:…
pooooky
  • 490
  • 2
  • 12
0
votes
3 answers

right syntax to have Nim string type to bool type

How do one convert string type to bool data type in Nim the best way ? var u,o :string o = "ooo" if not u : # <- illusration only
itil memek cantik
  • 1,167
  • 2
  • 11
0
votes
1 answer

Static linking C++ library with Nim C backend

I'm trying to build library with external C++ library (uchardet). I use the nimterop library for that. # wrapper.nim import std/os import std/strformat import nimterop/build import nimterop/cimport const libName = "uchardet" const libVer =…
Artem Klevtsov
  • 9,193
  • 6
  • 52
  • 57
0
votes
1 answer

To insert a Nim variable into its PCRE regex

How can we insert and interpolate a Nim variable into its regex (procedure re( ... )) just like Perl does ?
itil memek cantik
  • 1,167
  • 2
  • 11
0
votes
1 answer

Out of Memory Error When Calling DLL function

I'm trying to send an email to someone using python and Nim. I want for the script to work with a DLL, so I compiled my Nim code into a DLL. When loading the DLL into python and calling a function from it, it displays this error: out of…
nonimportant
  • 406
  • 4
  • 15
0
votes
1 answer

pthread_mutex_t {aka union }’ has no member named ‘abi’

I've been trying to write a pool of database connections based on a lockable queue (well, seq in this case) called POOL. I want to have POOL as a global variable and then use initConnectionPool to instantiate it. I've tried to do so with the code…
Philipp Doerner
  • 1,090
  • 7
  • 24
0
votes
1 answer

How do I re-build django's password hashing in nim?

I'm rewriting my webapplication from Python (Django) to Nim (Prologue). I want to keep using Django's database that it has provided me with thus far, but I'm struggling how to re-build the way Django encrypts the password. That is, according to…
Philipp Doerner
  • 1,090
  • 7
  • 24
0
votes
1 answer

Nim - Norm - How to get related fieldnames at compile time

Heyho, I am using norm, an orm in the nim programming language. I have 2 different models such as this: import std/options import norm type A {.tableName: "Surprise".} = ref object of Model name: string Surprise = ref object of…
Philipp Doerner
  • 1,090
  • 7
  • 24