Small improvement discussion: Use `let` to lock variable previously declared as `var`

2022-05-31 Thread exelotl
This issue doesn't really bother me, I just use `let x = block:` if I want to compute-then-freeze a variable. But I do have a similar issue which I wish I could solve: proc update(self: ptr Entity) = self.doStuff() if self.health <= 0.0: destroyEntity(self

Small improvement discussion: Use `let` to lock variable previously declared as `var`

2022-05-31 Thread cmc
> handful of variables in the local scope, some of which you might want to > "freeze" at different times. Felt it, couldn't phrase it, you did it for me- thanks! > Perhaps an explicit keyword can even increase readability. I most certainly think so!

Small improvement discussion: Use `let` to lock variable previously declared as `var`

2022-05-31 Thread federico3
The examples with only one variable used in a block or brackets looks a bit misleading to me. Often you have a handful of variables in the local scope, some of which you might want to "freeze" at different times. Writing code in awkward patterns or introducing complex macros just because we don

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Your are right! The assembler code generate by c compiler with simple object wrapper is almost same with the plain int.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
It is `distinct int` and `float`, not with `int`.

How to disable implicit convert float to int.

2022-05-31 Thread Yardanico
`distinct` would perform the same as an object/tuple with a single element if you compile with optimizations. Convertsions between `distinct T` and `T` are fundamental, I don't see why would you want to disallow them.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Use `distinct` for performance, disable `Price(3.6)` for safety.

How to disable implicit convert float to int.

2022-05-31 Thread Yardanico
I'm not sure if what you want is achievable with `distinct`, but as a workaround you can just make it a normal `object`, which would be better since you don't want to allow your user to directly convert from/to Price and int.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
I hope I can find way to prevent the code like this: proc Price(x: float) {.error.} Run But this doesn't compile.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
But this code compiles fine. type Price = distinct int var f = 3.6 var p = Price(f) echo p # 3, rather than 4 Run This is what I want to avoid.

How to disable implicit convert float to int.

2022-05-31 Thread Araq
There is no need to disable the conversion as it's only done for _literals_ anyway. This means that this does **not** compile: proc takesFloat(x: float) = discard var i = 44 takesFloat(i) Run

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Look at the following code. type Price = distinct int converter float_to_price(x: float): Price = x.toInt.Price let x = 3.6 let y = Price(x) # y = 3, I want to disable it let z: Price = x # z = 4, correct Run

nim-snappy, faster and simpler

2022-05-31 Thread arnetheduck
Someone asked about `nlvm` and the performance differences - in libraries like this, with CPU-heavy tight loops, the tricks that `nlvm` uses to generate more performant code for range checks and exception raising shines in particular: the `nlvm`-compiled benchmark of this library shows a 20% thr