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
> 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!
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
Your are right! The assembler code generate by c compiler with simple object
wrapper is almost same with the plain int.
It is `distinct int` and `float`, not with `int`.
`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.
Use `distinct` for performance, disable `Price(3.6)` for safety.
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.
I hope I can find way to prevent the code like this:
proc Price(x: float) {.error.}
Run
But this doesn't compile.
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.
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
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
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
13 matches
Mail list logo