[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 Cr

[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: Car(brand="Chrysler

[Python-Dev] Re: Words rather than sigils in Structural Pattern Matching

2020-11-22 Thread Greg Ewing
On 23/11/20 7:49 am, Daniel Moisset wrote: Look at the following (non-pattern-matching) snippet: event = datetime.date(x, month=y, day=z) The only names that are treated as lvalues there are to the left of an '='. The rules are a lot simpler. One of the Zen lines says "If it's hard to exp

[Python-Dev] Re: Questions about about the DLS 2020

2020-11-22 Thread Jim J. Jewett
I suppose that does follow from treating _ specially by not binding to it at all; I just hadn't thought through it. (I think my mental model had it wiping out the previous binding even if the "new" one wasn't available.) So I would prefer that this be stated explicitly in the PEP. (And maybe

[Python-Dev] Re: Matching syntax and semantics

2020-11-22 Thread Jim J. Jewett
I don't love the way it moves the variable name away from the capture location, but it does offer a decent solution for anonymous placeholder variables (other than _ or __), and makes it clear which variables are being bound (only those in front of an = sign) vs limiting potential matches (anyth

[Python-Dev] Re: Words rather than sigils in Structural Pattern Matching

2020-11-22 Thread Daniel Moisset
On Sun, 22 Nov 2020 at 00:31, Greg Ewing wrote: > On 22/11/20 6:47 am, David Mertz wrote: > > I'm convinced by Guido, > > Brandt, and others that the binding use will be far more common, so > > adding extra characters for the 90% case does not feel desirable > > Minimising the number of characte

[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 "erro

[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 a

[Python-Dev] Re: Words rather than sigils in Structural Pattern Matching

2020-11-22 Thread Marco Sulla
On Sun, 22 Nov 2020 at 01:27, Greg Ewing wrote: > That's a fairly complex bit of mental parsing to do > when reading a case. I agree, that's why I wrote pattern matching seems exotical to me. I was accustomed by Python to read the code as if it's wrote in simple English. I must admit this is not