C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [Proposal] switch for Pattern Matching

From: Andrew Tomazos <andrewtomazos_at_[hidden]>
Date: Wed, 26 Apr 2023 14:23:18 +1000
Funnily enough, this exact syntax was considered when pattern matching was
first discussed. There was a very lengthy discussion about whether to use
switch or whether to use a new keyword (like inspect), and one of the ways
that was suggested in the switch case was to use square brackets instead of
parens to differentiate a pattern switch from a normal switch. The support
for it was even considerable, but I think the inspect folks won out in the
end.

On Wed, Apr 26, 2023 at 12:38 PM Barry Revzin via Std-Proposals <
std-proposals_at_[hidden]> wrote:

>
>
> On Mon, Apr 24, 2023 at 2:09 PM Михаил Найденов via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> Hello,
>> Here is a short proposal to re-use `switch` for Pattern Matching.
>>
>
> Just so I'm clear. The argument is that introducing a new facility, with
> new semantics, under a new token (whether inspect or match) would be bad
> for teachability.
>
> So instead, you're proposing that we reuse an existing token (switch) to
> introduce two very different behaviors (statement vs expression, best match
> vs first match, fallthrough vs exactly one arm, integers vs more complex
> patterns, etc.), but since those different behaviors still need to be
> differentiated by the parser, you're proposing we do so by simply switching
> from parentheses to square brackets around the operand? And you're
> proposing that having 'switch' mean two very different things is better for
> teachability?
>
> Doesn't seem like a great idea to me.
>
> Barry
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-04-26 04:23:31