On 11/16/2020 11:57 AM, Tobias Kohn wrote:
1. This really comes down to how you look at it, or how you define
pattern matching. The issue here is that the concept of pattern
matching has grown into a large and somewhat diverse flock of
interpretations and implementations (as a side note: interestingly
enough, some of the only universally agreed-upon standards are to use
`_` as a wildcard and not to mark names that capture/bind values---which
are quite exactly the points most fiercely debatted here).
_ looks OK to me. I was not aware of the 'standard' for name usage.
But I just noticed the following:
Anyway, the paper presents the pattern matching structure we are
proposing as one of three major variants of pattern matching:
(a) Matching arguments to parameters in a function call,
Binding names are in the function definition and parameter signature,
which is the pattern. Except for default argument expressions, value
names are in the call that provided the data to be matched.
(b) Matching elements to elements in iterable unpacking,
Binding names are in the target pattern on the left. Value names are in
the data source expression on the right.
(c) Matching tree-like data to general patterns in a conditional
pattern matching structure.
Oh dear. We need both binding and value names in patterns. In
case BinOp(Num(left), '+', Num(right)):
obviously callable names BinOp and Num are treated as value names, with
their signatures providing subpatterns. The not-obviously-callable
names left and right are treated as binding names.
I think that Python matching should use the all-caps convention. I like
reusing the existing 'as x' syntax.
I see if-elif-else structures, with assignment expressions included, as
existing but limited conditional pattern matching structures. Binding
names are clearly marked with ':='.
---
Separate item: The Program 1 fact def needs a guard "if n > 1 and int(n)
== n" to not raise Recursion error for negative and fractional args.
--
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/LGGQ5GDOJMCQGA77XSRXVLEZSHPSOWV4/
Code of Conduct: http://python.org/psf/codeofconduct/