
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 ;-)

On Thu, 25 Jun 2020, 16:48 Eric Nieuwland, <eric.nieuwland@gmail.com> wrote:
And maybe also an additional operator:
if X matches Y: Z
This is really different from the PEP, but I like it, it reminds me of the if let matching in Rust.

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: <compare op 1> Y1: Z1 <compare op 2> Y2: Z2 … else: Q which would be the same as: if X <compare op 1> Y1: Z1 elif X <compare op 2> Y2: Z2 … else: Q Furthermore when X: <compare op 1> Y1 if C1: Z1 <compare op 2> Y2 if C2: Z2 … else: Q would be the same as: if X <compare op 1> Y1 and C1: Z1 elif X <compare op 2> Y2 and C2: Z2 … else: Q and so the PEP would need to define: - the 'when’ keyword - the 'matches' comparison
participants (2)
-
Eric Nieuwland
-
Evpok Padding