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
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/Q3GZ3YSI5MDP7DNRWW452STZ6KF6EMBT/
Code of Conduct: http://python.org/psf/codeofconduct/