Closed simonkrauter closed 1 year ago
I'm not sure this is a good idea. It seems like you're not familiar with named blocks (block a: ...
), which can be used for labeled breaks (break a
), so that you can for example break from a nested loop. Having unnamed block
s create a "break
boundary" is consistent with that.
As for your motivation, there's really no point in creating a new scope (i.e. using bock
) here.
You raise a good point, but a "block" is not a "scope". We could add a "scope" construct:
template scope(body) =
if true:
body
There are already similar constructs in Nim's sugar.nim
.
No for me. The benefit doesn't outweight the breakage that will ensue especially with no backward compatible solution.
@Araq Scoping needs non-dirty templates no?
@Araq Scoping needs non-dirty templates no?
No. Templates don't add/subtract scopes, there is .gensym
for symbol duplication (and .dirty
to inhibit it) but that's orthogonal to scoping.
Nope, it is even more confusing.
What's the point of {.dirty.}
here if you're not introducing new identifiers?
What's the point of {.dirty.} here if you're not introducing new identifiers?
There is none.
It is coming, see https://github.com/nim-lang/Nim/pull/20901
Abstract
block:
should have no effect to thebreak
statement and behave the same thanif true:
.Motivation
From other programming languages (C, C++) I am used, that introducing a new block with
{
and}
will not change the behavior of abreak
inside the block.C++ example:
Nim example:
In my opinion, Nim's behavior is against the Principle of Least Surprise.
It happend to myself several times, that I thought I can use the
block
keyword the same way than{
and}
in C/C++ to define a new variable scope.Description
Status quo: The
break
statement considers a block created byblock:
different to a regular block created for example byif true:
. A block created byblock:
affects the control flow, while a regular block does not.From the manual:
I propose to remove the interference between
block
andbreak
, when the block is not explicitly referenced by it's name.Examples
The following two examples are expected to work in the same way.
Backward incompatibility
Existing code would break. I have no idea for a backward-incompatible solution.