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

does putty support SET_ANY_EVENT_MOUSE , if yes how enable it?

i'm adding mouse support to a ncurses like library and i'm sending the control sequence: SET_ANY_EVENT_MOUSE (1003h) but it seems putty does not support it? It does support SET_BTN_EVENT_MOUSE (1002h) All other terminals i tried (xterm, vte bases…
enthus1ast
  • 2,099
  • 15
  • 22
0
votes
0 answers

How to create startProcess with a specific priority

I am using startProcess from osproc to create a process but it seems that the priority is hardcoded in the source code to normal. How to start a process with a lower priority? I've tried to copy paste startProcess with a specific priority in my…
Fabien
  • 1
  • 1
0
votes
1 answer

Best way to split an unsigned 64-bit integer to its bytes

I have an uint64 (what would be an unsigned long long in C) which I want to convert in an array of bytes. This is how I'm doing it right now (in Nim code): Value is typedef'd as unsigned long long Byte is typedef'd as unsigned char CD is an array…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
0
votes
0 answers

Best way to identify system library commands in Lexer/Bison

I'm writing an intepreter for a new programming language. The language's syntax is very simple and the "system library" commands are treated as simple identifiers (even if is no special construct, but a function like everything else - only…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
0
votes
0 answers

Validate function parameters based on given constraints

Before saying anything, please let me make it clear that this question is NOT language-specific but part of my work on an interpreter. Let's say we have an enum of Value types. So a value can be: SV, // stringValue IV, // integerValue AV, //…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
0
votes
1 answer

How to parse JSON in Nim (problem with long integers)?

I'm working on a piece of code in Nim that pulls a JSON object from the Shodan API. Here's the full JSON string from Shodan: {"city": "Alverca", "region_code": "14", "os": null, "tags": ["self-signed"], "ip": 1435234906, "isp": "Nos Comunicacoes,…
nxl4
  • 714
  • 2
  • 8
  • 17
0
votes
1 answer

Handling AM and PM in DateTime in Nim

I have a string like this 01/01/2019 8:43:55 AM # dd/MM/yy hh:mm:ss ?? After reading through the docs I concluded that the AM part had no corresponding entry in the formats provided. So that I would have to simply test to see if the string ended in…
SlightlyKosumi
  • 701
  • 2
  • 8
  • 24
0
votes
1 answer

How do I detect if an external hard drive is connected

I am trying to translate some code I use to run a backup to Nim (as part of learning the language). How do I detect if one of my external hard drives is connected (by name?) and then which drive letter my Windows 10 PC has assigned to it?
Alan James
  • 125
  • 5
0
votes
2 answers

Idiomatic way for single-expressions procs in nim

Why do I see proc simple(a, b: int) : int = result = a + b so often in nim code when it seems as if proc simple(a, b: int) : int = a + b would suffice? Is there any semantic difference between those two that I'm missing? The only reference to…
santa
  • 983
  • 9
  • 30
0
votes
1 answer

Rosencrantz is Routing DELETE Method not working?

my using Rosencrantz to Api Server. but DELETE method set is run compile to error not working? i Document copy and path , message, http method to Edited only nim versin : 0.19.6 rosencrantz : 0.3.8 import asyncdispatch, asynchttpserver, …
0
votes
1 answer

Getting a 400 bad request "missing consumer key" even though it is provided in the request body

So I am trying to write a pocket api library in Nim. I have the following code which makes a POST request to the pocket servers with a consumer key but I keep getting a 400 error saying that the consumer key is missing. import httpclient var…
Palash Nigam
  • 1,653
  • 3
  • 14
  • 26
0
votes
1 answer

Populate sequence containing NaN

Nim language question here. I want to read a series of floats from stdin (this example: 7, 1, 4, 4, nan, 4) and store it in a seq[float] type. The input may contain NaNs. But I fail to integrate such outliers. My code: var line: TaintedString …
smartmic
  • 661
  • 5
  • 15
0
votes
1 answer

Selecting arbitrary rows from a Neo matrix in Nim?

I am using the Neo library for linear algebra in Nim, and I would like to extract arbitrary rows from a matrix. I can explicitly select a continuous sequence of rows as per the examples in the README, but can't select a disjoint subset of…
Leo
  • 25
  • 1
  • 4
0
votes
1 answer

nim language ,gintro demo with two columns in a listview / gtktreeview and sortable

For nim language there is only one gui toolkit working for me and that is gintro. The democode listview compiles and runs nice on my netbsd. Source: http://ssalewski.de/gintroreadme.html But I need a listview(gtktreeview) with two columns, I looked…
0
votes
2 answers

batch created C interface in nimlang with template/macro?

BackGround In fact, I am porting FLTK C 1.3.3 for FreeBASIC to nimlang. Please note FLTK C 1.3.3 for FreeBASIC is a C interface upon the FLTK in CPP. Many functions in DLL meet the same similar name format, for example #inclib "fltk-c-1.3.3-64" '…
oyster
  • 537
  • 3
  • 15