C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Proposal regarding labeld breaking and continuation

From: hypatia.sva_at <hypatia.sva_at_[hidden]>
Date: Fri, 17 Feb 2023 14:40:59 +0000
I might be okay with

{
//....
  } // block:
outer:

But the arrows are not something I would deal with. Mainly because that
would be a change to the parser. My proposal does not change the syntax
parsing at all, it just gives an already existing thing (a label) a new
semantics.

The reason I also like it more on the opening brace is that it works on
forward looking parsers. Which, I would argue, in some sense includes
us: we read from top to bottom, from left to right, not the other way
around (at least in European languages). So it makes sense to me to have
the label first and then to refer to it. But having a label at the end
might be also okay, if its clear it refers to the braces.

The reason why I dont want it to be within the curly braces though is
that it refers to the block, not to something within the block. This is
especially important for nesting blocks, like:

block1: {
   block2: {
     block3: {
       if(a) continue block2;
       if(b) break block1;
       f(x);
       if(y) continue block3;
     }
     g(z);
   }
   h(w);
}

You can see that this is pretty difficult already, if we allow labels
all over the place it would be less readable, because its less clear to
which side they refer. Plus, "something { ... }" is already the default
syntax.

But I appreciate the other idea, is there any new contruct using arrow
notation? (the only thing Im aware of are trailing return types and
pointed-to structs).

Hypatia of Sva.




Am 17.02.2023 15:29 schrieb Frederick Virchanza Gotham via
Std-Proposals:
> On Fri, Feb 17, 2023 at 12:30 PM Hypatia (of) Sva via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> for(int i = 0; i < n; i++)
>> outer: {
>> for(int j = 0; j < n; j++) {
>> if(f(i,j)) break outer;
>> }
>> }
>
>
> A suggestion for alternative syntax:
>
> for ( unsigned i = 0u; i < n; ++i )
> { <- outer
> for (unsigned j = 0u; j < n; ++j )
> {
> if ( f(i,j) ) break outer;
> }
> }
>
> Maybe give the programmer the option of labelling the closing brace
> rather than the opening brace as follows:
>
> for (unsigned i = 0u; i < n; ++i )
> {
> for (unsigned j = 0u; j < n; ++j )
> {
> if ( f(i,j) ) break outer;
> }
> } <- outer

Received on 2023-02-17 14:41:02