Hi Brett,

Without having really looked at the history of all the languages we mention in the PEPs, I have a hunch that most of them had pattern matching from quite the beginning or an early stage on, indeed.  That being said, I think the question itself does not really make much sense, though.  Programming languages are rarely if ever just invented out of the blue these days, but evolve from other languages that have gone before them.  So, sure C++ and Objective-C both had objects and classes from the very beginning on, but if we take into consideration that they strongly build on C, we could argue just as well that OOP was a later addition to C.  It really depends on your point of view.

But since we are talking about different languages here, there is one example I could bring up.  In C#, the underscore is a perfectly legal variable name.  And yet, it is also used as a 'discard' [1] in newer versions.  Moreover, F#, which certainly uses the underscore as a wildcard, runs on the same platform as C# and thus has to deal with this, too.  Somehow, Microsoft and its developers seem able to cope with it.

If I may widen the topic here a bit and seize the opportunity to go beyond just answering your email: I must admit that I find this entire discussion about the wildcard pattern rather mind-boggling.  We seem all to accept the reality that ``match`` and ``case`` are context-sensitive keywords (i.e. they are both keywords and legal names) and that you cannot write ``123.bit_length()`` because the dot has several different meanings.  But when it comes to the underscore and the idea that *as a pattern* it might simply not store a value, it is considered an insurmountable obstacle to learning and understanding pattern matching?  Particularly because, after all, the underscore is in Python only a wildcard *by convention*?

I think pattern matching has a lot in common with 'recursion': if you see it for the first time, it can be very hard to wrap you head around it and understand what is going on or why anyone would want to do such a thing.  But once you understood it, it can be an extremely elegant solution to many problems.  So, I really can fully understand a lot of the reservations brought forward about this feature and various aspects of it.  And there were enough good and valid points brought up by the community, which we then integrated into and respected in our overhauled design---but that the wildcard pattern causes so much grief really is entirely beyond me...

So, yes, most languages had pattern matching quite from the outset on (or not at all).  But then, again, Python is about the only language I know to have introduced 'type' annotations so late in life rather than from its very beginning.  It came at the cost of using the colon for something different than compound statements or dictionaries.  If we consider how much annotations have been expanded in more recent versions of Python and how many tools make good use of it, I would call that a pretty successful move, though---even though all other languages might have had type annotations from their very birth.

Kind regards,
Tobias

P.S. Sorry, I guess this turned out to be not so much a reply to your comment alone, as much more a reply to many a message and discussion that has been posted here over time.

[1]  https://docs.microsoft.com/en-us/dotnet/csharp/discards

Quoting Brett Cannon <br...@python.org>:

 

On Mon, Nov 16, 2020 at 9:03 AM Tobias Kohn <ko...@tobiaskohn.ch> wrote:

_Hi Mark,

Thank you for your interest and the questions.

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)._

_How many of those languages added pattern matching /later/ and not at the earliest stages of the language (if not from the beginning)? And for those that added it later, how many of those didn't already have a convention surrounding "_"? My suspicion is "not many" and "not many". 😉_
    _ _
    _-Brett_
_______________________________________________
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/KP2TVEAPDT553VXL4QEUOTYBHHMDUXSK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to