[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-22 Thread Guido van Rossum
On Sun, Nov 22, 2020 at 5:03 PM Jim J. Jewett wrote: > I think your changed constructor: > > class Car: > def __init__(self, manufacturer, variant): > self.brand = manufacturer > self.model = variant > > is a particularly good example, and the PEP should specify whether: >

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-22 Thread Ethan Furman
On 11/22/20 5:00 PM, Jim J. Jewett wrote: I think your changed constructor: class Car: def __init__(self, manufacturer, variant): self.brand = manufacturer self.model = variant is a particularly good example, and the PEP should specify whether: Car("Chrysler", "PT

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-22 Thread Jim J. Jewett
I think your changed constructor: class Car: def __init__(self, manufacturer, variant): self.brand = manufacturer self.model = variant is a particularly good example, and the PEP should specify whether: Car("Chrysler", "PT Cruiser") is matched by:

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-22 Thread Daniel Moisset
Others have replied with most of this covering my opinion but there's a point I'd like to highlight here On Fri, 20 Nov 2020 at 14:23, Mark Shannon wrote: > Hi Daniel, > > On 20/11/2020 10:50 am, Daniel Moisset wrote: > > (... snipping for brevity ...) > > > > 1. You mention a goal about

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-22 Thread Brian Coleman
Regarding the difficulty which some people have respecting class patterns and dictionary patterns, I would like to draw attention to a similar feature in JavaScript, object destructuring. JavaScript does not have pattern matching but object destructuring is closely related. Take the example of

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-21 Thread Tobias Kohn
Hi David and Steve, There is hardly anything that needs to be added to your comments, of course.  However, I consider these explicitly named attributes in the class pattern to be one of the most difficult aspects of our pattern matching proposal, which is something I just want to briefly

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-21 Thread Tobias Kohn
Hi Steve, Thank you very much for your comments here.  This is certainly not the first time I feel that you not only have an excellent insight into a topic, but also manage to make your points very clearly and succinctly.  Your car example highlights the background of the proposed

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-21 Thread Guido van Rossum
On Mon, Nov 16, 2020 at 6:41 AM Mark Shannon wrote: > I believe that a pattern matching implementation must have the following > properties: > > * The semantics must be precisely defined. > * It must be implemented efficiently. > * Failed matches must not pollute the enclosing namespace. > *

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-21 Thread Andrew Svetlov
If you don't want the overlapping with the existing syntax angle brackets can be used: match eggs: case Spam: ... On Sat, Nov 21, 2020 at 7:31 PM David Mertz wrote: > On Sat, Nov 21, 2020 at 12:23 PM Steven D'Aprano > wrote: > >> Clearly Spam(a=1, b=2) does not necessarily result in an

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-21 Thread David Mertz
On Sat, Nov 21, 2020 at 12:23 PM Steven D'Aprano wrote: > Clearly Spam(a=1, b=2) does not necessarily result in an instance with > attributes a and b. But the pattern `Spam(a=1, b=2)` is intended to be > equivalent to (roughly): > > if (instance(obj, Spam) > and getattr(obj, a) == 1

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-21 Thread Steven D'Aprano
On Fri, Nov 20, 2020 at 02:23:45PM +, Mark Shannon wrote: > Why force pattern matching onto library code that was not designed for > pattern matching? It seems risky. Can you give a concrete example of how this will "force" pattern matching onto library code? I don't think that anyone has

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-21 Thread Mark Shannon
On 20/11/2020 6:57 pm, Tobias Kohn wrote: Hi Daniel and Mark, Sorry for being slightly late to the party, but please let me add a few remarks of my own to the discussion here. *1. Must have precisely defined semantics* Yes, there are some aspects that we left open intentionally.  Most

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-20 Thread Terry Reedy
Mark, did you get the response I sent to hotpy.org 4 days ago? Is that a real address? I ask because the typos I reported are still there and trying to visit hotpy.org fails. -- Terry Jan Reedy ___ Python-Dev mailing list -- python-dev@python.org

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-20 Thread Tobias Kohn
Hi Daniel and Mark, Sorry for being slightly late to the party, but please let me add a few remarks of my own to the discussion here. 1. MUST HAVE PRECISELY DEFINED SEMANTICS Yes, there are some aspects that we left open intentionally.  Most prominently the question of how often the

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-20 Thread Mark Shannon
Hi Daniel, On 20/11/2020 10:50 am, Daniel Moisset wrote: Hello again Mark, I took some time looking in more detail at your proposal, and these are my thoughts. I'm writing with the assumption that this proposal describes some "internal" representation of match statements which is never

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-20 Thread Steve Holden
Fair enough. On Fri, Nov 20, 2020 at 11:45 AM Thomas Wouters wrote: > > > On Fri, Nov 20, 2020 at 8:38 AM Steve Holden wrote: > >> On Thu, Nov 19, 2020 at 8:08 PM Brett Cannon wrote: >> >> All I will say is just because we aren't *required* to implement it in >> __future__ that doesn't mean

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-20 Thread Thomas Wouters
On Fri, Nov 20, 2020 at 8:38 AM Steve Holden wrote: > On Thu, Nov 19, 2020 at 8:08 PM Brett Cannon wrote: > > All I will say is just because we aren't *required* to implement it in > __future__ that doesn't mean we can't or shouldn't. Everything should be > done to underline the tentative

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-20 Thread Daniel Moisset
Hello again Mark, I took some time looking in more detail at your proposal, and these are my thoughts. I'm writing with the assumption that this proposal describes some "internal" representation of match statements which is never exposed to the users (so I'd mostly steer away from

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-19 Thread Steve Holden
On Thu, Nov 19, 2020 at 8:08 PM Brett Cannon wrote: > > > On Thu, Nov 19, 2020 at 5:16 AM Steve Holden wrote: > >> On Wed, Nov 18, 2020 at 7:04 PM Daniel Moisset >> wrote: >> >>> [sorry for the duplicate, meant to reply-all] >>> >>> Thank you for this approach, I find it really helpful to put

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-19 Thread Brett Cannon
On Thu, Nov 19, 2020 at 5:16 AM Steve Holden wrote: > On Wed, Nov 18, 2020 at 7:04 PM Daniel Moisset > wrote: > >> [sorry for the duplicate, meant to reply-all] >> >> Thank you for this approach, I find it really helpful to put the >> conversation in these terms (semantics and guiding

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-19 Thread Steve Holden
On Wed, Nov 18, 2020 at 7:04 PM Daniel Moisset wrote: > [sorry for the duplicate, meant to reply-all] > > Thank you for this approach, I find it really helpful to put the > conversation in these terms (semantics and guiding principles). > > It does help to rationalise discussion ;-) > [...] >

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-18 Thread Daniel Moisset
[sorry for the duplicate, meant to reply-all] Thank you for this approach, I find it really helpful to put the conversation in these terms (semantics and guiding principles). This is not an answer to the proposal (which I've read and helps me contextualize) but to your points below and how they

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-17 Thread Mark Shannon
Hi Guido, On 16/11/2020 4:41 pm, Guido van Rossum wrote: Thanks Mark, this is a helpful and valuable contribution. I will try to understand and review it in the coming weeks (there is no hurry since the decision is up to the next SC) but I encourage you to just put it in PEP form and check

[Python-Dev] Re: The semantics of pattern matching for Python

2020-11-16 Thread Guido van Rossum
Thanks Mark, this is a helpful and valuable contribution. I will try to understand and review it in the coming weeks (there is no hurry since the decision is up to the next SC) but I encourage you to just put it in PEP form and check it into the PEP repo. Because I only skimmed very briefly, I