IMO the block syntax is good enough but I tried to come up with a template as an exercise. The code below works but can it be improved?
How to avoid passing the variable name (e.g. `foo`) to the template? As far as
I know this isn't possible.
template shadowvar(varname: untyped, initStmt: typed, body: untyped):
untyped =
block:
var `varname` {.inject.} = initStmt
body
`varname`
proc test() =
let foo = shadowvar(foo, 5):
foo += 2
echo foo
test()
Run
