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

nimble : Warning: Using project local deps mode or how to switch deps mode for nimble

Happy new year, everyone ! :) I tried to run nimble list -i command, but mistyped with nimble list -l and now when I run this nimble list -i command again to get all installed packages ... I get: Warning: Using project local deps mode ... and…
How2
  • 365
  • 1
  • 6
0
votes
1 answer

Pythonic pip freeze in Nim or how to list installed packages?

How to pip freeze command looks for Nim's package manager nimble ?
How2
  • 365
  • 1
  • 6
0
votes
1 answer

Error: identifier expected, but got: paramStr(1)

So, I had this code: import std/os import system/io echo paramStr(1) if declared(paramStr(1)) == true: echo It exists else: echo It doesn't exists And then while I was compiling this error ocurred: Error: identifier expected, but got:…
0
votes
2 answers

Is there a file object to get path or name of a file in Nim?

Let's say, I would like to use a single object to represent a file and I'd like to get the filename (or path) of it so that I can use the name to remove the file or for other standard library procedures. I'd like to have a single abstraction which…
ChrisoLosoph
  • 459
  • 4
  • 8
0
votes
1 answer

Encode and Decode rfc2396 URLs in Nim

I'm working on an application that will work as a cli trash app (I know trash-cli exists, this is a personal project :) ), one of the problems I encountered is that your trash info (when you move something to trash, an info file is generated to…
Netsu
  • 1,399
  • 1
  • 7
  • 18
0
votes
1 answer

How do ref objects work in Nim and difference between new and common constructor

I was trying to understand references in Nim comparing ref to pointers in C (I know that I should not compare these two languages but I understand way better in this way). Then something came up to my mind... Are ref objects always allocated in the…
std124_lf
  • 134
  • 2
  • 9
0
votes
0 answers

Nim: `Unable to process type: nnkBracketExpr` when unmarshal to type with Table[string, seq[string]]

The following type Response: type Response* = object name: string vers: string features: Table[string, seq[string]] which I'm trying to unmarshal a json to: let json = parseJson(text) let test = to(json, Response) However…
victorzki
  • 45
  • 1
  • 7
0
votes
1 answer

Why Git gives the error "Resource temporarily unavailable (code: 11)" when simultaneously executing multiple instances?

I have an automated test that tries to clone a bunch of specific revisions from the local Git repository by using the following asynchronous Nim procedure. proc cloneSpecificRevision(downloadMethod: DownloadMethod, url,…
bobeff
  • 3,543
  • 3
  • 34
  • 62
0
votes
2 answers

implementing setInterval/clearInterval in nim

I have the following code which run the passed proc in an interval, and return a clearInterval proc to stop the run, as follow: proc runInterval(cb: proc, interval: int): Future[proc()] {.async.} = var stop_run = false while not(stop_run): …
georgehu
  • 186
  • 1
  • 12
0
votes
1 answer

How to write accesors for kind Variants in Nim

Trying to write accesors to get a value of an object with a kind member, I get invalid indentation error in a macro I am not sure why I imagine I might be building macros wrong but if there is a better way to abstract type kinds in objects it would…
shuji
  • 7,369
  • 7
  • 34
  • 49
0
votes
2 answers

Convert uint8 to int

What is the best way to go about converting a uint8 into a normal int I want to do some work with an rgb histogram, but I can't find a correct approach to the final piece here (updated to rm stbi lib) proc obc*(image1, image2: string) = type…
SlightlyKosumi
  • 701
  • 2
  • 8
  • 24
0
votes
1 answer

How can I create a lookup table of different procedures in nim?

In python, functions are "first class citizens" and can be passed to functions/methods as arguments. Let's say I wanted to start writing a basic remote procedure call(rpc) library in python, I might start by creating a dictionary that maps the…
RattleyCooper
  • 4,997
  • 5
  • 27
  • 43
0
votes
0 answers

How to CosmoNim (GCC) on Solus Linux? (segfault)

What methods or tools can I use to help figure out the below issue? I'd like to use CosmoNim on Solus Linux. It works on other linux distributions, but produces executables that segfault when built on Solus Linux. CosmoNim works for me on Ubuntu…
GGibson
  • 354
  • 2
  • 9
0
votes
1 answer

Error importing faster_than_requests on windows

I recently installed the python package faster_than_requests ver 21.3.3 from pypi on python ver 3.9.2 on windows. Upon importing the package as mentioned in the docs, I get the following traceback >>> import faster_than_requests Traceback…
0
votes
1 answer

Nim: Spawned Function Cannot Have a Var Parameter, but Argument to acquire Must Be Var

I've been using threadpool in Nim and have encountered the requirement that spawned functions cannot accept a mutable argument. However, I want to pass a proc a Lock, which in turn has to be mutable, according to the type of acquire. The only way to…