[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-03 Thread David Mertz
There have been a number of comments in this thread, and some slight variations in the idea. I'm afraid that it all looks awkward to me, so far. I understand trying to work out the smallest change that would allow the style, but it just feels "bolted on" in a bad way. I believe that if Python get

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-03 Thread Neil Girdhar
This is very cool, well thought-out, and solves an important problem. I would have definitely benefited from Python having better pattern matching. As an idealist though, if you're going to add pattern matching, why not just do it completely? I agree that your proposal would be useful in some

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-03 Thread Andrew Barnert via Python-ideas
> On Jan 2, 2020, at 18:34, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> > wrote: > > On 1/2/20 3:07 PM, Random832 wrote: >> On Thu, Jan 2, 2020, at 13:22, Dan Sommers wrote: > >>> What about "if except" (any time I can eliminate a "not," that's a >>> good thing): >> ... is this meant to be

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-02 Thread Dan Sommers
On 1/2/20 3:07 PM, Random832 wrote: > On Thu, Jan 2, 2020, at 13:22, Dan Sommers wrote: >> What about "if except" (any time I can eliminate a "not," that's a >> good thing): > > ... is this meant to be for the doesn't-throw case or does-throw? ... >> >> if except x: >> y That would

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-02 Thread Random832
On Thu, Jan 2, 2020, at 13:22, Dan Sommers wrote: > What about "if except" (any time I can eliminate a "not," that's a good > thing): wait, is this meant to be for the doesn't-throw case or does-throw? how are we eliminating the not? > if except x: > y > > which could even leave r

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-02 Thread Dan Sommers
On 1/2/20 12:55 PM, Andrew Barnert via Python-ideas wrote: > On Jan 2, 2020, at 06:32, Random832 wrote: >> Mainly, you had mentioned you felt like "if try" had a 'smell' to it >> but couldn't figure out what it is, and I was trying help identify >> that, and... well, after thinking about it mor

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-02 Thread Andrew Barnert via Python-ideas
On Jan 2, 2020, at 06:32, Random832 wrote: > > Mainly, you had mentioned you felt like "if try" had a 'smell' to it but > couldn't figure out what it is, and I was trying help identify that, and... > well, after thinking about it more, I realized - "if try" may not have many > uses, but "if no

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-02 Thread Random832
On Wed, Jan 1, 2020, at 21:49, Andrew Barnert wrote: > On Jan 1, 2020, at 13:23, Random832 wrote: > > > > Neither of these constructs seems to be particularly useful outside the > > other one, > > Yes, and you already quoted me as saying that. I think I read "not proposing them separately" as

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
On Jan 1, 2020, at 13:23, Random832 wrote: > > Neither of these constructs seems to be particularly useful outside the other > one, Yes, and you already quoted me as saying that. > which suggests to me they should not be orthogonal in the way you have > proposed. Is there a good reason for wa

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
> On Jan 1, 2020, at 08:32, Guido van Rossum wrote: >  > Here's a proposal for JavaScript that seems to be going through > standardization: https://github.com/tc39/proposal-pattern-matching The JS solution is interesting, but I’m not sure how well it works for a different language. Python is c

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
On Jan 1, 2020, at 07:03, Steven D'Aprano wrote: > > On Tue, Dec 31, 2019 at 02:28:26PM -0800, Andrew Barnert via Python-ideas > wrote: > >>if try 0, y, z := vec: >># do yz plane stuff >>elif try x, 0, z := vec: >># do xz plane stuff >>elif try x, y, 0 := vec: >>

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
>> On Jan 1, 2020, at 04:21, Steven D'Aprano wrote: >> >> On Tue, Dec 31, 2019 at 05:18:59PM -0800, Andrew Barnert via Python-ideas >> wrote: >> >> Some languages use special syntax to mark either values or targets: >> let x, K, let z = vec >> x, @K, z = vec >> But the simplest solution is t

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 21:35, Guido van Rossum wrote: > > There were match proposals in the past — have you looked those up? Maybe they > solve your problem without that syntax — or maybe they would benefit from it. Most of the existing proposals require a lot more syntax—a new form using two or

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Random832
On Tue, Dec 31, 2019, at 22:18, Andrew Barnert via Python-ideas wrote: > I’m just feeling out whether either one is so horrible that any larger > proposal (which I don’t have in anywhere near ready-to-share form yet) > would have to be rejected on that basis. (Which I think is a serious > possib

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Guido van Rossum
Here's a proposal for JavaScript that seems to be going through standardization: https://github.com/tc39/proposal-pattern-matching Here's the end of an older python-ideas thread: https://mail.python.org/archives/search?mlist=python-ideas%40python.org&q=pattern+matching+reprise On Tue, Dec 3

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Dan Sommers
On 1/1/20 10:02 AM, Steven D'Aprano wrote: # Fail() is a function that raises an exception; # __ is a special predefined Pattern that always matches. result = match(vec, # object to match Pattern(0, 'y', 'z'), handle_yz, Pattern('x', 0, 'z'), handle

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Steven D'Aprano
On Tue, Dec 31, 2019 at 02:28:26PM -0800, Andrew Barnert via Python-ideas wrote: > if try 0, y, z := vec: > # do yz plane stuff > elif try x, 0, z := vec: > # do xz plane stuff > elif try x, y, 0 := vec: > # do xy plane stuff > elif x, y, z := vec: >

[Python-ideas] Re: Target-and-expression lists and if-try

2020-01-01 Thread Steven D'Aprano
On Tue, Dec 31, 2019 at 05:18:59PM -0800, Andrew Barnert via Python-ideas wrote: > Some languages use special syntax to mark either values or targets: > > let x, K, let z = vec > x, @K, z = vec > > But the simplest solution is to nothing: you have to stick it in an > expression that isn

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread David Mertz
> > > class MatchType(type): > def __eq__(self, other): > return self == type(other) > > Or I even want to match: > > type[int], y < 42, z = vec > > Well, I can’t think of a language where you can actually match that way. > That doesn’t necessarily mean we should disallo

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Guido van Rossum
There were match proposals in the past — have you looked those up? Maybe they solve your problem without that syntax — or maybe they would benefit from it. On Tue, Dec 31, 2019 at 19:20 Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > Let me make this bit a little clearer: > >

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
Let me make this bit a little clearer: > On Dec 31, 2019, at 17:54, David Mertz wrote: > > So your syntax gets me maybe 20% of what I'd want to do if we had pattern > matching. I’m not proposing either of these changes in its own, because I don’t have any use for either one on its own. (Or fo

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 17:54, David Mertz wrote: > >  >> On Tue, Dec 31, 2019 at 8:23 PM Andrew Barnert via Python-ideas >> wrote: > >> > K = 42 >> > x, K, z = vec >> Yes. I’m surveying the way other languages deal with this to try to figure >> out what might fit best for Python. >> Some langua

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread David Mertz
On Tue, Dec 31, 2019 at 8:23 PM Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > > K = 42 > > x, K, z = vec > Yes. I’m surveying the way other languages deal with this to try to figure > out what might fit best for Python. > Some languages use special syntax to mark either value

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 15:52, Greg Ewing wrote: > > On 1/01/20 11:28 am, Andrew Barnert via Python-ideas wrote: > >> The first is to extend unpacking assignment to target-or-expression lists. >> Like this: >>x, 0, z = vec >> But >> it doesn’t bind anything to the second element; instead, it c

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Greg Ewing
On 1/01/20 11:28 am, Andrew Barnert via Python-ideas wrote: The first is to extend unpacking assignment to target-or-expression lists. Like this: x, 0, z = vec But it doesn’t bind anything to the second element; instead, it checks if that element is 0, and, if not, raises a ValueError.

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 14:58, Soni L. wrote: > > >> On 2019-12-31 7:28 p.m., Andrew Barnert via Python-ideas wrote: >> >> The second is an “if try” statement, which tries an expression and runs the >> body if that doesn’t raise (instead of if it’s truthy), but jumps to the >> next elif/else/stat

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Soni L.
On 2019-12-31 7:28 p.m., Andrew Barnert via Python-ideas wrote: Every so often, someone suggests that Python should have a pattern matching case statement like Scala, C#, Swift, Haskell, etc. Or they just suggest that “Python needs algebraic data types” but end up concluding that the biggest

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
To make things a little more concrete (still without actually defining the library or searching for better motivating examples), here’s a slightly rewritten example from the Scala tutorial: def showNotification(notification: Notification) = { notification match { case Ema