how to use Natural type?

2022-09-08 Thread Prestige
`Some definitions, including the standard ISO 8-2,[3][a] begin the natural numbers with 0, corresponding to the non-negative integers 0, 1, 2, 3, ...,` What is misleading?

if-else VS case-else VS case

2022-08-04 Thread Prestige
I'm not sure, but I'll provide my runtimes of these benchmarks: `nim r -d:release foo.nim`: if-else: 0.086073489 case-else: 0.10265143 case-all: 0.14253516 Run `nim r foo.nim`: if-else: 0.346636164 case-else: 0.249107282 case-all: 0.313689

Mastering Nim: A complete guide to the programming language

2022-06-23 Thread Prestige
Just placed my order, excited about the book and happy to support the development of this language. I still hope we can get a digital copy eventually, so I can more easily reference it while I'm programming. > I didn't want to waste his excellent cover for this book as more are planned. Lookin

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

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

`=destroy` ref object of RootObj?

2022-04-07 Thread Prestige
Thanks, that worked. I did not expect that behavior

`=destroy` ref object of RootObj?

2022-04-06 Thread Prestige
That does appear to work, but I'm running into an issue trying it for my particular use case: Why would there be an implicit construction of the `=destroy` hook, perhaps because `Image` is a `ptr object` or `Font` is a `pointer`? Even if that's the case, how would I gain control of the deconstr

`=destroy` ref object of RootObj?

2022-04-06 Thread Prestige
I have not found a way to create a destroy hook for objects that inherit from RootObj (or even futher down an inheritance hierarchy): type Foo = ref object of RootObj proc `=destroy`(foo: Foo) = discard Run Is there a way to accomplish this? * * * For

Can there be an else clause on a template (or macro)?

2022-03-02 Thread Prestige
Is there a way to do the following? I thought I'd seen something like this before, but have been unable to replicate this sort of syntax. import std/random randomize() template customIf(body: untyped) = if rand(10) >= 5: body customIf: e

Editor issues, nimsuggest reporting false errors?

2022-01-13 Thread Prestige
Editing nim code since 1.6.0 has been a pain due to (false) errors being reported by nimsuggest. See Has this not been an issue for others? I've disabled LSP support since 1.6.0, and have been compiling frequently to check for errors. Editor suppor

Maze solver benchmark - How would you optimize?

2021-12-14 Thread Prestige
I tried the BoolSeq from that post but it actually made the map generation about twice as slow - I merged PMunch's solution. I am curious why a `main` function increases speed, I wouldn't think it'd make a difference

Maze solver benchmark - How would you optimize?

2021-12-13 Thread Prestige
They were very similar (on my machine), about 11 or 12 milliseconds depending on the run

Maze solver benchmark - How would you optimize?

2021-12-13 Thread Prestige
I've ported a maze benchmark from Rust to Nim, here Out of curiosity/for fun, how would you improve (i.e. speed up) the solution?

repr a ref object with a property from a C library

2021-10-18 Thread Prestige
Thank you! I'll update the wrapper later when I have some time. Really appreciate the help.

repr a ref object with a property from a C library

2021-10-16 Thread Prestige
I'm actually needing to use the addr of the object, but it breaks in a similar fashion. I should have mentioned that. Illegal storage access when doing `foo[].addr`

repr a ref object with a property from a C library

2021-10-16 Thread Prestige
I'm using [chipmunk7](https://github.com/avahe-kellenberger/nim-chipmunk) for a project, and have ran into an issue using `repr` on an object with a `PolyShape`. This doesn't seem to be particular to this one type. I'm unsure if this is a problem with my code, the wrapper, or a Nim bug. Exampl

Life is a struggle - a struggle with Nim (video)

2021-06-23 Thread Prestige
Have you reported that GC issue?

Proposed table changes - get and getOrDefault

2021-06-12 Thread Prestige
I'd like to gather opinions on changes I want to propose for the tables module. Please leave any thoughts or suggestions you may have. ### getOrDefault Example: import tables let table = {1: "one", 2: "two"}.toTable proc creat

Anybody using `self` or `this` for procedures operating on "class" style object types?

2021-02-03 Thread Prestige
I use `this` as a first param (I don't like using `using`). I think it's fine, why not?