Mastering Nim: A complete guide to the programming language

2022-06-22 Thread xflywind
Awesome! Congraulations! Finally Nim has a printed book after reaching v1. Btw will Amazon show table of contents on the introduction of the book?

Mastering Nim: A complete guide to the programming language

2022-06-22 Thread pietroppeter
Great news and congrats! 🎉 👏🥳 And wow, even plans for more! 🤩 An idea could be to publish a blogpost in Nim website with the presentation of the book, maybe the full TOC and an excerpt? ✨ Could be a nice way to spread around the news! 💥 Ps: of course already bought it and it tells me it arrive

Mastering Nim: A complete guide to the programming language

2022-06-22 Thread Araq
> An idea could be to publish a blogpost in Nim website with the presentation > of the book, maybe the full TOC and an excerpt? ✨ Sure, we're working on it.

Mastering Nim: A complete guide to the programming language

2022-06-22 Thread Araq
> The cover is a bit bland though, coincidentally, George Lemon posted his mock > up cover not so long ago somewhere here on the forums... I didn't want to waste his excellent cover for this book as more are planned. ;-)

Mastering Nim: A complete guide to the programming language

2022-06-22 Thread Zoom
Great news! Congrats on the release. Writing and _finishing_ a book is no small accomplishment. I'm sure it's as useful and witty as the language itself. The cover is a bit bland though, coincidentally, George Lemon posted his mock up cover not so long ago somewhere here on the forums...

Threading error: calling procs off objects (httpbeast)

2022-06-22 Thread nepeckman
Yeah that was exactly my assumption, thanks for the clarification :)

Threading error: calling procs off objects (httpbeast)

2022-06-22 Thread dom96
A `threadvar` needs to be initialised manually per-thread. I guess your expectation is that assigning the value in one thread will assign the same one in all threads, that is not the case. You will only assign it in the main thread. Best way to do what you want is to create a proc for each threa

Mastering Nim: A complete guide to the programming language

2022-06-22 Thread Araq
My book is about to become available: If you like to support Nim, please consider buying my book. If you think that you don't need it because you already know everything about Nim, buy it and read **Part III: Mastering Macros**. If you fear that the book

Threading error: calling procs off objects (httpbeast)

2022-06-22 Thread nepeckman
I'm pretty new to Nim's threading capabilities, and I'm running into what I'm sure are some basic problems. I'm working on an httpbeast based web framework, trying to call procs off object fields, and I'm getting "SIGSEGV: Illegal storage access" errors. The code runs fine with threads off, so i

Is it possible to "mock" function calls? (For testing purposes)

2022-06-22 Thread Araq
> TBH, I don't know why Nim doesn't allow shadowing. I like shadowing very much and we should indeed go the full way. The reason why Nim doesn't allow it is historical. Back then it wasn't as clear cut that it's a good idea and even today many oppose it ("it is confusing / error prone").

Example code with multithreading and channels is failing

2022-06-22 Thread jasonfi
I get an exception right at the start: channels_test.nim(223) channels_test channels_test.nim(116) concurrencyTests channels_test.nim(50) addReceiverThreadWithChannel SIGSEGV: Illegal storage access. (Attempt to read from nil?) Run

Example code with multithreading and channels is failing

2022-06-22 Thread jasonfi
I've seen the same exception, where it looks like receiver threads are getting messages intended for other threads. I have no idea why.

Example code with multithreading and channels is failing

2022-06-22 Thread mashingan
Sorry, I run your example and it's immediately failing with this message: D:\test.nim(203) receiver Error: unhandled exception: Message received is invalid: myMsg.str (This is a test for: 19) != "This is a test for: 27" [ValueError] D:\test.nim(203) receiver Error: unh

Example code with multithreading and channels is failing

2022-06-22 Thread mashingan
`createThread` is creating and running it immediately and you're calling it each time you invoke `addSenderThreadWithChannel`

Example code with multithreading and channels is failing

2022-06-22 Thread jasonfi
Why is that a problem though? The call to `addSenderThreadWithChannel` isn't in parallel with anything that would interfere. Can you explain what you would change so I can understand what you're saying?

Example code with multithreading and channels is failing

2022-06-22 Thread jasonfi
I was going to use channel.lock at a later stage. The code shouldn't try to write to the channel.list in multi-threaded code. The code to create threads and channels is currently single-threaded.

Is it possible to "mock" function calls? (For testing purposes)

2022-06-22 Thread Zoom
Easy peasy! :D import std/[random, sugar] randomize() proc genString*(length: int): string = for i in 0 ..< length: result &= rand('a'..'z') assert genString(12).len() == 12 template mock(f: proc; m: untyped) = template mockImpl{

Example code with multithreading and channels is failing

2022-06-22 Thread mashingan
In your gist, you're not using the channel.lock itself. Try to lock/unlock (or acquire/release?) when reading or writing to channel.list. You can also try separate lock for fetching and assigning the channel to the list, but using the same lock for fetching/assigning channel should be simpler.

Example code with multithreading and channels is failing

2022-06-22 Thread Clonk
Have you run `nimble install threading` ?

Example code with multithreading and channels is failing

2022-06-22 Thread jasonfi
I read that too, I tried importing threading/channels but it's not found. Is there another way to import it?

Example code with multithreading and channels is failing

2022-06-22 Thread Clonk
Not directly an answer yo your question but I was under the impression that the recommended multi-threading primitive to use are the ones in ; which are supposed to be a "better" implementation (I guess).

Example code with multithreading and channels is failing

2022-06-22 Thread jasonfi
I wrote a test program that uses multiple sender and receiver threads that communicate via channels. The sender -> channel -> receiver chain is 1:1:1. However I want to store all threads and channels in tables, so that I can access any one of them by a key. This is to eventually build more compl

Any way to determine the GC at runtime?

2022-06-22 Thread Vindaar
Why would you (need to?) do it at runtime if you can already error out at compile time? (if it's not clear how: when defined(gcArc) or defined(gcOrc): # do things else: {.error: "Please compile with `--mm:arc` or `--mm:orc`."} Run

Any way to determine the GC at runtime?

2022-06-22 Thread jasonfi
Great, thanks

Any way to determine the GC at runtime?

2022-06-22 Thread sekao
You can do it [like this](https://github.com/nim-lang/threading/blob/49562fa0d393e765823b2ea96ca14fbb9889a566/threading/channels.nim#L86-L87). Change `when` to `if` to do it at runtime (though why not at compile time?).

Is it possible to "mock" function calls? (For testing purposes)

2022-06-22 Thread Prestige
It's pretty common practice to do something like this for e.g. integration testing that involves network/database calls, calls to 3rd party services, etc

Any way to determine the GC at runtime?

2022-06-22 Thread jasonfi
I'd like to confirm that the GC is ORC/ARC or raise an exception. Thanks.

Is it possible to "mock" function calls? (For testing purposes)

2022-06-22 Thread Vindaar
Soo, uuhhh, I was just bored on a train. And "I have no idea what I'm doing" applies rather heavily. But... I just ported: to Nim to try it out for this. To my utter surprise it actually works. I'm pretty sure it's _not_ a good idea to use this for tes

Is it possible to "mock" function calls? (For testing purposes)

2022-06-22 Thread Araq
There is no good way to "mock" things except for turning the call you want to mock into using a proc variable so that you can override it. Having said that, old-school functional/procedural programming doesn't need much mocking. There is data and there is code, in order to test the code setup t

Is it possible to "mock" function calls? (For testing purposes)

2022-06-22 Thread Prestige
## Preface In other languages, testing libraries exist which allow you to "mock" a function (see ). Mocking a function means swapping out a function your program would normally call, with another function. E.g. it would find all invocations of `foo()` and