<div dir="ltr">Whereas I find it a deal-breaker for 'as'.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 23, 2018 at 3:15 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 04/23/2018 03:04 PM, Tim Peters wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[Ethan Furman <<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>>]<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
So I really like being able to make the assignment in the expression, but I<br>
have a really hard time parsing it with the name first.<br>
<br>
...<br>
<br>
On the other hand, if it were using the "as" keyword:<br>
<br>
if (x - xbase as diff) and (gcd(diff, n) as g) > 1:<br>
return g<br>
<br>
I would parse as:<br>
<br>
if<br>
x - x_base<br>
as diff<br>
and<br>
gcd(diff, n)<br>
as g<br>
> 1:<br>
return g<br>
<br>
For me at least, the last is much more readable. Thinking about it some<br>
more, the problem (or maybe just my problem) is that I see an "if" or<br>
"while" and the I look for the thing that is True or False, and using the<br>
":=" syntax the first thing I see is a placeholder for a result that doesn't<br>
exist yet, making me constantly scan backwards and forwards to put all the<br>
pieces in the correct place.<br>
<br>
With "as", it just flows forwards.<br>
</blockquote>
<br>
I can read it fine either way, and don't much care. A possible<br>
advantage of an "as" operator is that its precedence could be set to<br>
bind just a tad stronger than comparisons (which include "is" and "is<br>
not" in Python), and then, e.g.,<br>
<br>
if f() as result is not None:<br>
do something with result<br>
<br>
could work as intended. So long as people can't get "assignment<br>
_statements_" out of their heads,<br>
<br>
if result := f() is not None:<br>
<br>
groups instead as<br>
<br>
if result := (f() is not None):<br>
<br>
which would almost never be _intended_. Maybe spelling it "as"<br>
instead could break that.<br>
<br>
However, against "as" is that its current use in "with" statements<br>
does something quite different:<br>
<br>
with f() as name:<br>
<br>
does not bind the result of `f()` to `name`, but the result of<br>
`f().__enter__()`. Whether that "should be" fatal, I don't know, but<br>
it's at least annoying ;-)<br>
</blockquote>
<br></div></div>
"as" does something slightly different in each of its current incantations, but the one thing that they all have in common is taking some thing on the left and giving it the name on the right:<br>
<br>
- imports -> thing on left gets name on right<br>
- exceptions -> exception that matches class on left gets name on right<br>
- with -> result of left.__enter__() gets name on right<br>
<br>
I see very little harm in adding<br>
<br>
- expression-binding -> eval(thing on left) gets name on right<br>
<br>
--<br>
~Ethan~<div class="HOEnZb"><div class="h5"><br>
<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/options/python-dev/guido%<wbr>40python.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>