On 7/16/2020 9:51 PM, Tobias Kohn wrote:
Hi Everyone,
I feel there are still quite a few misconceptions around concerning PEP
622 and the new pattern matching feature it proposes. Please allow me
therefore to take another attempt at explaining the ideas behind PEP 622
with a different approach. Bear in mind that I naturally cannot cover
everything, though, and that some parts presented here are still
slightly simplified.
Thank you Tobias. I am a fan of looking at things from multiple
viewpoint. For 200 years, physicists argued about whether light is
waves or particles, before discovering that 'neither' and 'both' were
more correct.
1. Function Overloading
2. Visitor Pattern and Dispatch > 3. Shape and Structure
[snip, snip, snip]
In an assignment statement, the code to the left of '=' is a 'target
list' of 'target's, with some idiosyncratic rules. Even though it
might, misleadingly, be called a 'target expression', it is not an
expression to be evaluated. Similarly, the code between parentheses in
a def statement is a 'parameter list' of 'defparameter' and special
symbols, with other idiosyncratic rules. Both could be called 'binding
lists' or more generally, 'binding structures'.
To me, the important point of your point is that 'case' is somewhat
analogous to 'def', and that the stuff between 'case' and ':' is a
binding structure. We should call this structure a 'match structure'.
It is misleading and confusing to call it a 'match expression'. A match
structure consists of a 'match list' of 'match items' or 'matcher's and
an optional "'if' <condition>".
Matchers have a 3rd, new, and larger set of idiosyncratic rules. The
optional condition is an escape hatch for when expressing the intended
match constraint and corresponding match set is difficult or worse using
the match rules.
As with target and parameter items, untagged simple name matchers are
(and I now see, should be) binding targets. (The parameter list tags
are ':' for types and '=' for default values.) Unlike assignment
targets, dotted names and subscriptings are not binding targets. Like
parameter lists, match lists include literals. Match lists also include
syntactic structure not seen in the other binding structures.
--
Terry Jan Reedy
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/NNZ67OMAV2CDV7GSX64SOLUAERJSF5HP/
Code of Conduct: http://python.org/psf/codeofconduct/