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

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

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

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

2020-11-21 Thread David Mertz
I'm not sure it matters in all the threads. But my underlying opinion is that we SHOULD have a mechanism to use a plain name (that has an assigned value in the scope) as a value in match patterns, not only as binding targets. However, in contrast to Nick Coghlan, I do not think access should be t

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

2020-11-21 Thread Guido van Rossum
On Sat, Nov 21, 2020 at 9:52 AM David Mertz wrote: > So in my mind, if I had the choice, it is a decision between a sigil and a > word to indicate "no, really use this name as a value!" I like a word > better, but none of the current keywords really make sense, so it would > need to be a new word

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

2020-11-21 Thread David Mertz
On Sat, Nov 21, 2020 at 2:47 PM Guido van Rossum wrote: > On Sat, Nov 21, 2020 at 9:52 AM David Mertz wrote: > >> So in my mind, if I had the choice, it is a decision between a sigil and >> a word to indicate "no, really use this name as a value!" I like a word >> better, but none of the current

[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. > * Obje

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

2020-11-21 Thread Glenn Linderman
On 11/21/2020 9:47 AM, David Mertz wrote: So in my mind, if I had the choice, it is a decision between a sigil and a word to indicate "no, really use this name as a value!" I like a word better, but none of the current keywords really make sense, so it would need to be a new word. I suggested "

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

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

2020-11-21 Thread Marco Sulla
On Sat, 21 Nov 2020 at 18:52, David Mertz wrote: > So in my mind, if I had the choice, it is a decision between a sigil and a > word > to indicate "no, really use this name as a value!" I like a word better, but > none > of the current keywords really make sense, so it would need to be a new wor

[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: Words rather than sigils in Structural Pattern Matching

2020-11-21 Thread Henk-Jaap Wagenaar
On Sat, 21 Nov 2020 at 19:58, Glenn Linderman wrote: > Don't () already indicate an expression to be evaluated? > Does it? [(a, b)] = [(0, 1)] print(a) gives 0 as output. ___ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an ema

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

2020-11-21 Thread Greg Ewing
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 characters is not the only consideration. Readability counts too, and I

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

2020-11-21 Thread Greg Ewing
On 22/11/20 1:07 pm, Henk-Jaap Wagenaar wrote: On Sat, 21 Nov 2020 at 19:58, Glenn Linderman > wrote: Don't () already indicate an expression to be evaluated? Does it? [(a, b)] = [(0, 1)] Presumably a comma would be needed to match a 1-tuple. case (x):