Mutability of loop variables

2023-11-19 Thread billtubbs
I assume this was implemented since this now runs without the error mentioned above: import strutils let s = "a \n b\n c \n" for line in s.splitLines: let line = line.strip echo '>', line, '<' Run Output: >a< >b<

Mutability of loop variables

2023-11-19 Thread Araq
> 7 YEARS LATER <

How to iterate over a sequence using a pointer to avoid making copies of every item

2023-11-19 Thread Araq
It does not copy. But usually people use `ref object` for big objects anyway out of habit.

How to iterate over a sequence using a pointer to avoid making copies of every item

2023-11-19 Thread billtubbs
Ah, I think I found the answer to my own question [here](https://forum.nim-lang.org/t/2721). So is the loop variable by default immutable? And therefore not a copy probably.

How to iterate over a sequence using a pointer to avoid making copies of every item

2023-11-19 Thread ElegantBeef
type Person = object name: string age: int data: array[0.., int] # big data proc getNames(people: openArray[Person]): seq[string] = for val in people.items: echo cast[int](val.data.addr) result.add val.name var a = [Per

How to iterate over a sequence using a pointer to avoid making copies of every item

2023-11-19 Thread billtubbs
I'm completely new to Nim so go easy on me here. My goal is to replace performance-limiting parts of Python scripts (using Nimpy and Nimporter) and so part of the appeal is that it is a high level language with similar syntax and idioms to Python. First impressions are great... but then I tripp

overload operator `+=` for private member

2023-11-19 Thread Araq
> I would like to preserve the '+=' and '-=' operators for structure members. What does that mean.

overload operator `+=` for private member

2023-11-19 Thread mimonot
I'm writing a wrapper for a C library. I would like to preserve the '+=' and '-=' operators for structure members. Maybe you can use a template or a macro?

overload operator `+=` for private member

2023-11-19 Thread PMunch
This sounds like a job for [dot operators!](https://nim-lang.org/docs/manual_experimental.html#special-operators-operator-nimdoteq). They can be a bit tricky, but they can certainly do what you need

What's stopping Nim from going mainstream? (And how to fix it?)

2023-11-19 Thread ElegantBeef
_Then again comparatively speaking Nim only has 10 packages_ :D

Question from one of my customers.

2023-11-19 Thread blackmius
I think it depends on how fast you can start maintaining customer applications. If it is quick change customer will think he can do same thing with someone else: find new programmer let him small time to learn nim and he got new person maintaining his code. moreover for secret even you already k

What's stopping Nim from going mainstream? (And how to fix it?)

2023-11-19 Thread xigoi
I personally feel like Rust's ecosystem is a negative. Everything has hundreds of transitive dependencies. In Nim, I've never seen a package with more than ten.

os:any vs os:standalone

2023-11-19 Thread Araq
I can confirm that `os:standalone` is the old way, don't use it.

os:any vs os:standalone

2023-11-19 Thread khaledh-nim
That was my guess as well. Versions of the compiler manual up to [1.0](https://nim-lang.org/1.0.0/nimc.html#nim-for-embedded-systems) mention `os:standalone`. As of version [1.2](https://nim-lang.org/1.2.0/nimc.html#nim-for-embedded-systems), the manual mentions `os:any`, which lines up with th

os:any vs os:standalone

2023-11-19 Thread auxym
My understanding is that `any` supercedes `standalone` and that `standalone` should probably be deprecated, but I'm not 100% sure. FYI here is the PR that added `os:any`:

os:any vs os:standalone

2023-11-19 Thread khaledh-nim
I've been in the process of developing a kernel in Nim. I've made a lot of progress and I'm planning to write a blog series about it. But when I came back to some of the basics, I'm not sure I quite understand the difference between `--os:any` and `--os:standalone`. The section on [embedded sys

Question from one of my customers.

2023-11-19 Thread AntonioFS
Hello. Thank you very much for your feedback. I look forward to hearing from other people on this forum as well, so that I can form a solid opinion. Best regards. Antonio F.S.

Question from one of my customers.

2023-11-19 Thread sky_khan
It's been 10 years since I got registered to this forum. Even then it had been around several years. Not like Google or Mozilla but it has few corporate sponsors and it has a permissive MIT license which corporate firms like to use. So I dont expect it to die soon.

Question from one of my customers.

2023-11-19 Thread sky_khan
Because, maybe, Nim can be one of most practical and productive language, depending on task at hand? It has its own drawbacks too of course but it's learning curve is not steep. If you are somewhat familiar with Python (and possibly Pascal), just a few days should be enough to make your own deci

Question from one of my customers.

2023-11-19 Thread AntonioFS
Hello. Thank you for your response. The thing is, it is not for me as a technician (because I like what I am learning), but for the client to whom I must give guarantees of language presence in the market and confidence in terms of corporate prospects. Best regards. Antonio F.S.

gensym redeclaration

2023-11-19 Thread sky_khan
Your code is kinda ambiguous, not clear if you want to create two seperate sequences or two references to same sequence. Still, seems like a compiler bug to me. I mean, it should be caught at nim compilation phase.

gensym redeclaration

2023-11-19 Thread dlesnoff
I have a strange error with the following program: import sequtils proc luDecomposition(n: int) = # Créer des matrices L et U var lower, upper: seq[seq[float]] = newSeqWith(n, newSeq[float](n)) # Exemple d'utilisation let n = 3 luDecomposition(n)

mixed typed varargs?

2023-11-19 Thread ElegantBeef
`import std/macros macro printThings(x: varargs[typed, `$`]): untyped = result = newCall("echo", newLit"Mine: ") for arg in x: result.add arg printThings "Hello", [1, 2, 3, 4,], 10, 200, 300, true ` Run

Question from one of my customers.

2023-11-19 Thread AntonioFS
Hello. A few months ago someone introduced me to a client, owner of a small group of companies. He told me that their programmer was no longer there and that they had to maintain and create new applications in...Nim! (hence I am currently studying it). It was the first time I knew about this l

mixed typed varargs?

2023-11-19 Thread Lantos
thanks for the replys template printThings(args: auto) = for arg in `args`.fields: echo arg Run works but interested in how [typed] Run might look like

Templates: How to gensym proc names, and inject variables in asm?

2023-11-19 Thread Araq
You need to have the `for iv in 0..<32:` inside the macro.

Exceptions not being handled with libuv: bug or what?

2023-11-19 Thread dadadanix
I couldn't find anything about `nimTestErrorFlag`, so I supposed it was like a built-in function initially. As a I said previously a possible solution to make the program handle the exception is to stop the event loop by calling `uv_stop`, but I couldn't find a way to add a global exception hand

slice assignment doesn't work when converter is present

2023-11-19 Thread veksha
Hi. Can someone tell me what is happening here. the following code works, but when i uncomment converter (which is needed for another task) code does not compile > > #converter toString(a: seq[byte]): string {.inline.} = cast[ptr > string](a.addr)[] > > var query = @[byte 1,2,3] >

Templates: How to gensym proc names, and inject variables in asm?

2023-11-19 Thread Charles
With this snippet: import macros ... macro interproc(interruptVector, name, wrapper) = quote do: proc `name`() {.exportc, asmNoStackFrame.} = asm """ pushq `interruptVector` jmp `wrapper` """ interruptProcedures[`interruptVector`

Exceptions not being handled with libuv: bug or what?

2023-11-19 Thread dadadanix
As I have showed on the code, I do in fact already check if an error occurs. I have tried to purposely throw an exception with also the `nimTestErrorFlag`, but still nothing really changes. proc onConnect(req: ptr uv_connect_t; status: cint) {.cdecl.} = let fut = cast[Future

Templates: How to gensym proc names, and inject variables in asm?

2023-11-19 Thread Araq
Use a macro.

Exceptions not being handled with libuv: bug or what?

2023-11-19 Thread Araq
Well why would the C code check the error flag after it called your callback?

overload operator `+=` for private member

2023-11-19 Thread exelotl
I don't think it can be done in that case. Well, there's an unsafe way of doing it if you know that the two types are binary compatible and of the same size. type Obj = object m: cint static: doAssert(sizeof(cint) == sizeof(int32)) proc `m`*(o: v

What's stopping Nim from going mainstream? (And how to fix it?)

2023-11-19 Thread nimian
Nim is too many things to too many people. I feel like Nim would do well if it tried to break into CNCF landscape. ebpf backend would be also great

overload operator `+=` for private member

2023-11-19 Thread mimonot
Thank you. This works well if the "m" is the right type. But what if the private “m” is of a different type and needs conversion? type Obj = object m: cint proc `m`*(o: var Obj): var int = int(o.m) # Error Run

overload operator `+=` for private member

2023-11-19 Thread aEverr
add proc m*(o: var Obj): var int = o.m Run

mixed typed varargs?

2023-11-19 Thread Araq
You can use `varargs[typed]` and a macro, no need for json.

Memory leakage caused by the use of asyncftpclient's rter process

2023-11-19 Thread Araq
Feel free to report bugs properly, we have extensive tests for leaks like and they are green.

Memory leakage caused by the use of asyncftpclient's rter process

2023-11-19 Thread termer
You can expect anything built with asyncdispatch to leak memory under ORC. Unfortunately that's just the state of things right now. The asyncftpclient lib might be extra bad, but keep in mind that asyncdispatch has memory issues and you often have to run `GC_fullcollect` manually to free memory

overload operator `+=` for private member

2023-11-19 Thread mimonot
I recently started learning the Nim language and ran into a problem. I can define operators to get and set a private member of an object, but I need the "+=" operator. How to properly define the "+=" operator for a private member of an object? type Obj* = object m: in

Nim Community Survey 2023

2023-11-19 Thread SolitudeSF
no examples then? or do you think that everything that gets complained about on forum should be changed?

Nim Community Survey 2023

2023-11-19 Thread tsojtsoj
Feedback from individuals is not the same as a poll.

mixed typed varargs?

2023-11-19 Thread Lantos
Ahh, thanks.

mixed typed varargs?

2023-11-19 Thread uzo2005
This is my hacky solution to this specific use-case. template printThings(args: auto) = for arg in `args`.fields: echo arg printThings ("words", "to", "print", 123) Run [check it out](https://play.nim-lang.org/#ix=4LTQ) I ran into this exact

Templates: How to gensym proc names, and inject variables in asm?

2023-11-19 Thread Charles
Hello again, I'm trying to create a template that substitutes a proc in a loop, so I can create the same proc with minor variations. This is the relevant snippet: const erroringVectors = [8, 10, 11, 12, 13, 14, 17, 21, 29, 30] var interruptProcedures: array[32, uint64]

mixed typed varargs?

2023-11-19 Thread demotomohiro
> A varargs parameter is an open array parameter that additionally allows a > variable number of arguments to be passed to a procedure. The compiler > converts the list of arguments to an array implicitly And an array elements can have only

mixed typed varargs?

2023-11-19 Thread Lantos
Hi, are mixed typed varargs possible? proc printThings(args: varargs[string | int]) = for arg in args: when arg is string: echo arg when arg is int: echo arg printThings( "words", "to", "prin

What's stopping Nim from going mainstream? (And how to fix it?)

2023-11-19 Thread ingo
To be honest, I don't see a problem. Yet that won't hinder me to dream. There is the NIR survey. I don't understand half the options, but they make me think: If it can offer a REPL and that REPL runs everything written in plain NIM as if it where a scripting language, what could be done with tha

Nim Community Survey 2023

2023-11-19 Thread freeflow
Its the general impression I have from reading this forum over the past few years. Citing a few recent changes doesn't change that impression.