I wrote:
Guido van Rossum wrote:
Eric Nieuwland wrote:
I have some doubt about the keyword: ‘match' seems to be at odds with 'for', 'while', 'with', 'if' as it is more of an action. It's more like 'try' but that statement has a completely different structure.
Well, 'try' is also an action. :-) Many people have tried to come up with a different keyword here, but nothing has been found that comes even close to the simplicity of match. Plus, several other languages (Scala, Rust) use it too (which is further evidence that it's a natural fit).
It may also be evidence for not being able to come up with a more accurate keyword.
Reading through the PEP once more I noticed I was understanding
match X: case Y: Z
as
when X: matches Y: Z
which also to me seems to reflect the close relation to an if-elif-elif… construction.
This would almost naturally imply the possibility of:
when X: matches Y: Z ... else: Q
And maybe also an additional operator:
if X matches Y: Z
Not a native speaker I don't have a reasonable alternative, though.
Me neither, but I speak it quite fluently now, and 'match' really feels like it fits well here.
Trying ;-)
Thinking of this over the weekend, I think the following might be even more flexible and powerful:
when X: