c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Match statement

Open data-man opened this issue 3 years ago • 4 comments

Many "modern" languages have match. C++: P1371R2, C++17 matchit.cpp Python: the-match-statement Rust: patterns

It would be nice to add it to C3.

data-man avatar May 07 '22 18:05 data-man

I think the added complexity is not worth it. Note that there is already partial support for what match does as case supports both ranges and non-constant expressions.

Consequently both case 45 .. 60: and case foo(): works.

lerno avatar May 07 '22 18:05 lerno

the added complexity is not worth it

The complexity is in implementation, but not in usage.

case supports both ranges and non-constant expressions.

Sure, I know. Let case stays for simple types.

data-man avatar May 07 '22 18:05 data-man

Complexity in implementation is complexity in learning. I have not seen sufficient usefulness of it. The actual uses of it over an extended case is as far as I can tell fairly minimal.

lerno avatar May 07 '22 19:05 lerno

I've also added:

switch
{
  case x == 100:
    ...
  case x > 100:
    ...
}

What use cases do you want match for?

lerno avatar Jul 21 '22 00:07 lerno

Can we close this @data-man ?

lerno avatar Sep 24 '22 19:09 lerno

Close it if you want. And I've added Ruby's docs with many useful examples.

data-man avatar Sep 25 '22 05:09 data-man

Probably this can be implemented by macros but single underscore isn't allowed as identifier.

data-man avatar Sep 25 '22 06:09 data-man