> On Jan 2, 2020, at 18:34, Dan Sommers <[email protected]> 
> 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 for the doesn't-throw case or does-throw? ...
>>>     if except x:
>>>         y
> 
> That would be the does-throw case.  Read it as "if there's an exception
> evaluating x, then do the following."

But then you have the opposite of what you need. You want “if it matches this, 
do that with these bindings”, not “if it doesn’t match this, do that (with 
these failed bindings)”.

Also, you can’t chain these up and keep trying patterns until one succeeds, or 
default if all of them fail; instead you can only chain them up and keep trying 
patterns until one fails, or default if they all succeed.

So, this syntax might be useful for other things, but not for pattern matching.

>> ... how are we eliminating the not?
> 
> I changed "not try" to "except," thus eliminating the "not."

But there’s no “not try”, just a “try”. We want to run code if the try 
condition succeeds, which is positive, not negative.

Or, if you prefer, it’s a double negative, and you’ve removed one of the 
negatives:

   if try (x, 0, z) := vec:
       xz_stuff(x, z)

… would be roughly equivalent to:

   try:
       x, 0, z = vec
   except ValueError.
       pass
   else:
       xz_stuff(x, z)

What you’ve given is a way to put code in the one place where we didn’t want 
any (but had to put a “pass” just for syntactic reasons) without putting code 
in the place we did.


_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/5HOJJFQIQ25JZLPPGBOZTEMDDTAMGBSJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to