blocks are also useful for some horrible things. for example:
var x = acquire_hounds()
block:
defer: release_hounds(x)
.. stuff go here ..
Run
this seems less interesting at first until you realize they can go in to
templates or macros. which means you can use templates to create critical
sections that will release some resource when the body ends for any reason. so
you can build your own python context managers.
or something my math lib does which is amazing and horrifying at the same time:
template broadcasted*[T](v: Vec3[T]; op: untyped): untyped =
## Returns a vector where `op` has been called on each element.
var x, y, z {.noinit.}: T
block:
let it {.inject.} = v.x
x = op
block:
let it {.inject.} = v.y
y = op
block:
let it {.inject.} = v.z
z = op
vec(x, y, z)
Run
which is a template that runs the same body 3 times, operating on a value
called `it`, but actually works on different definitions of `it` at the same
time.