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.
552
questions
1
vote
1
answer
105
views
Function comparing two strings slower in nim than python
I am a novice in nim, but want to use it to write functions to use in python. I am using nimpy and nimporter for importing nim functions to python.
This function in python:
def pcompare(a, b):
...
0
votes
1
answer
30
views
How do I iterate over the fields of a ref object in nim?
I have a ref object type and would like to iterate over all of its fields and echo them out.
Here an example of what I want:
type Creature* = ref object
s1*: string
s2*: Option[string]
n1*:...
0
votes
1
answer
32
views
Jsony newHook has `SIGSEGV: Illegal storage access. (Attempt to read from nil?)` when deserializing into ref-objects
I am writing a web-application and am deserializing via jsony into norm-model-object types.
Norm-model-types are always ref objects. Somehow my code which is very similar to the default example in ...
-1
votes
1
answer
39
views
How do I call Mix_GetError from the nim SDL2 Mixer bindings?
There are multiple references in the nim SDL2 mixer.nim file to
Error messages can be retrieved from Mix_GetError().
However, I can't seem to find this function defined in the mixer.nim file
How can I ...
1
vote
1
answer
40
views
How to properly read and parse data from Firebase in Nim?
I have a database in Firebase which currently I can access through CURL like this
curl "https://mydb.firebaseio.com/my_data.json?auth=XKJYED78634jsvdffwu7riugwer"
I want to make a Nim script ...
0
votes
1
answer
54
views
How do I access an object field via its field name in string form?
I'm figuring out at compile-time the name of a specific field of an object that I want to access. Before I compile, I do not necessarily know which field that is going to be, so I just have that field ...
1
vote
1
answer
59
views
Check if a string ends with something, case insensitive?
I want to check if a file has a certain extension, which I can do with filename.endsWith(".ext"). But I also want to match against .EXT. How can I do this?
0
votes
1
answer
58
views
how to pass +, -, etc. to macro in Nim
I want to do something like this macro in Nim
#define BINARY_OP(op) \
do { \
double left = getLast(); \
double right = getLast(); \
push(right op left); \
} while (false)
I ...
1
vote
1
answer
101
views
How to generate C headers from Nim
I wrote a library which is intended to be used in C as well.
Compiling the library to a .dll/.so/.lib itself is well documented and works as expected.
However, I cannot find anything regarding the ...
1
vote
1
answer
84
views
nim, how to get the result of multithreading execution immediately, without any delay?
I'm absolute beginner in Nim Lang.
I have been practicing python for the last 4 years, before that there was a sharp.
Nim is great, but I don't understand how to comprehend him yet.
I'm trying to ...
0
votes
1
answer
27
views
Norm - Querying entries within generics causes type mismatch compilation error
I write a web application in the nim programming language and use norm as my ORM.
There I follow the standard repository pattern, meaning you have associated with a given URL a controller which calls ...
1
vote
1
answer
39
views
How do you align string containing accents in nim
In Nim, how do you align strings containing accented characters?
For example the following code
var maxLen = 20
var s1 = alignLeft("John le Carré", maxLen)
var s2 = alignLeft("John le ...
1
vote
1
answer
39
views
The runtime constant in forward declaration
How do we do runtime constant in forward definition/declaration by any way around (tried hard not work on using let)
let n :int
proc m : int =
let i=1
var u=n+i
n=m()
error for this or for other ...
1
vote
0
answers
46
views
Change Directory and exit program in that directory in Linux
I have a simple program that I run from a terminal which changes the working directory (via setCurrentDir) and performs some other work which creates some new files in that folder.
When the program ...
1
vote
1
answer
61
views
Nim lang syntax a = b = c = 7
How to solve error on syntax var a = b = c = 7 being one RHS value for many LHS just like in C:
int a,b,c ;
a = b = c = 7 ;
so on Nim lang:
Error: invalid indentation
Help out, thanks in advance
0
votes
1
answer
77
views
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 == ...
-1
votes
1
answer
47
views
Prologue -Webframework - How to set thread-local variables for logging when compiling with `--threads:on` flag?
I am writing a web-application in nim, using the web-framework prologue and the ORM norm. I've found that the log-messages of prologue and norm that normally appear in the terminal when starting up ...
0
votes
1
answer
54
views
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 ?
1
vote
1
answer
64
views
How to implement a macro to apply a template repeatedly with some common and some varying arguments
The use case is the following: I have a config object and a main object. Main object contain a field of config type. Config object has many fields and I want to make them accessible from main object ...
1
vote
1
answer
94
views
How to get what is on the terminal in Nim lang
How can I store what is on the terminal (console) as a string in Nim?
For example, let's say my console is showing this:
Success: Execution finished
Success: All tests passed
(base) piero@...
0
votes
2
answers
71
views
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
...
0
votes
1
answer
74
views
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 ...
0
votes
1
answer
67
views
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 ?
0
votes
2
answers
110
views
Simple syntax to print out Nim address
How to print out Nim address
just like in C:
int array[] = { 7, 8, 9 };
printf(" %p ", (void *)&array);
? the try:
var
arr = newSeq[array[2,int]](2)
refVar = addr arr
echo ...
0
votes
1
answer
61
views
PTR DWORD in nim lang
what is the problem of This Code:
import winim
let CurrentProcessID = GetCurrentProcessId()
var SessionID :DWORD
let result1 = ProcessIdToSessionId(CurrentProcessID,cast [ptr DWORD](SessionID))
echo ...
0
votes
1
answer
55
views
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 ...
0
votes
1
answer
83
views
Nim must be able to get one character input just like in Bash
How do Nim get one character input just like in Bash ? :
read -n1 -p "Enter x to exit " # or
read -N1 -p "Enter x to exit "
1
vote
1
answer
56
views
How can one do a pixel by pixel comparison of an image created by cairo and an image loaded from a file
I have some code in nim that creates a picture using Cairo (https://github.com/nim-lang/cairo). I would like to compare that picture to another using diffimg (https://github.com/SolitudeSF/diffimg, ...
2
votes
1
answer
60
views
Use of declaration and/or definition array of tuple
How to have and declare/define array of tuple[ string , seq[ array[2,string] ] ]
Illustration is
var
a : seq[tuple[ string , seq[array[ 2, string]] ] ]
a[0] = [ "foo", [ ["...
1
vote
2
answers
63
views
Nim : How to constrain an existing type
I have a question about type definition.
I would like to restrict an existing type to enforce certain additional criterion.
For example, I would like to construct a type for a DNA string.
A DNA strand ...
1
vote
1
answer
65
views
Nim regex to perform once not global replace
How do we ask Nim regex to perform once not global replacing it with a specific string (e.g. let sided by Perl syntax) ?
import std/nre
var o="foo bar blah !"
echo o.replace( re"(\...
2
votes
1
answer
114
views
How to pass command line arguments to a task?
How do I pass command line arguments to a nimble task? For example, say I have the task
task mytask, "my task":
echo &"my task {args}"
When I run
nimble mytask --foo --bar
...
2
votes
1
answer
48
views
How to hide all Nimble and Nim outputs including errors?
How can I hide all Nimble and Nil outputs including errors?
I used this command nimble build --silent, but it still throws errors when there are errors.
How can I disable that?
0
votes
3
answers
218
views
Nim have to convert string to int the simplest
How have Nim to convert string to int the simplest native way without a coder put import std...
so on ?
var
s = "99"
si :int
i = 1
si = s ... # <- ? picturing
i += si # <- ...
0
votes
2
answers
47
views
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. [...
1
vote
1
answer
49
views
Error when compiling Nim file with --os:any
When I try to compile any Nim file with --os:any I get this error:
osalloc.nim(218, 10) Error: Port memory manager to your platform
Why does this error pop up and how can I fix it?
In addition, when ...
1
vote
2
answers
53
views
Have to count a character occurrence in Nim string type
How to count a character occurrence in string in Nim, mainly using its native statements prior go to module ? eg.
var
str = "Hello World"
c : int
c = numChar( "o", str ) # <- ...
0
votes
1
answer
76
views
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(
...
1
vote
1
answer
58
views
Nim cannot do check regex object with failed captured group
How to check one of nre object member with a failing captured group such:
if m.get.captures[1] == "" : echo "group 1 is empty"
still fails, results in
nre.nim(342)
...
1
vote
1
answer
51
views
Pop first element of OrderedSet
How do I pop the first element of an OrderedSet?
0
votes
3
answers
108
views
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
0
votes
0
answers
125
views
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
...
0
votes
1
answer
43
views
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 ?
2
votes
2
answers
63
views
Do a Nim regex modifier just like Perl one
How is Nim regex PCRE modifier done as in Perl itself is e.g.
/foobar/i
/ foo bar /x
/foobar.*/s
etc ?
Please explain correctly doing such on Nim
Thanks much in advance
0
votes
1
answer
65
views
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 ...
1
vote
1
answer
95
views
Add the ability to use tabulation in Nim
Yes, we can convert tabs to spaces via Sublime, VS-Code and etc, it's not a big problem.
But what if I want to get rid off this additional action ?
Found answer by adding this line to .nim file :
#? ...
1
vote
1
answer
56
views
pthread_mutex_t {aka union <anonymous>}’ 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 ...
1
vote
1
answer
85
views
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 ...
2
votes
1
answer
81
views
Nim 1.4 Compile - Modify default compile flags on MacOS - issue with clang ld: library not found for -lrt
For some reason on my Mac when I am using nim 1.4 with clang it always builds with the -lrt compile flag which breaks since that's not on Macs.
So every time I need to do nim c --listCmd [my nim file]....
1
vote
1
answer
43
views
How to map seq[type] to seq[type.field] with a generic fieldname?
I am building a web application and using an ORM called norm. As such, I have an SQL database with a bunch of tables, all of which correspond to various Models that I have in nim. Often enough, they ...