<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, May 13, 2018 at 12:06 PM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, May 12, 2018 at 08:06:02PM -0400, Neil Girdhar wrote:<br>
> On Sat, May 12, 2018 at 2:28 PM Steven D'Aprano <<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>> wrote:<br>
<br>
> > > * there are no difficult mental questions about evaluation order, e.g.,<br>
> > > in a bracketed expression having multiple assignments.<br>
> ><br>
> > Aren't there just?<br>
> ><br>
> > x = 1<br>
> > print( x + x given x = 50 )<br>
> ><br>
> ><br>
> > Will that print 100, or 51? Brackets ought to make it clearer:<br>
> ><br>
> > (x + x given x = 50) # this ought to return 100<br>
> > x + (x given x = 50) # this ought to return 51<br>
> ><br>
> > but if I leave the brackets out, I have no idea what I'll get.<br>
> ><br>
> <br>
> It has to be 100, or else outer parentheses change how an expression is<br>
> evaluated.<br>
<br>
Whether that it right or wrong, you're missing the point. You said that <br>
we don't have to care about evaluation order. But we do: even if your <br>
analysis is correct, not everyone will realise it. I didn't.<br></blockquote><div><br></div><div>I think the way to think about "given" is the same way you think about "for" and "if" clauses:</div><div><br></div><div>(x + x for x in it)</div><div><br></div><div>(x + x if condition else y)</div><div><br></div><div>(x + x where x = f(y))</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
And I still don't, because I think your analyse is wrong.<br>
<br>
"Outer parentheses" is a red herring. I should have written:<br>
<br>
(x + x) given x = 50 # this ought to return 100<br>
x + (x given x = 50) # this ought to return 51<br>
<br>
and now there are no outer parentheses to worry about. The question is <br>
now whether "given" binds more tightly than + or not.<br>
<br>
We get to choose the precedence, and whatever we choose, it will <br>
surprise (or annoy) some people, and more importantly, some people <br>
simply won't know, and will have to ponder the difficult question of <br>
what the evaluation order is.</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
This is already true today with code that has side-effects. I can <br>
simulate "given" using exec. It only works in the module scope:<br>
<br>
# another_expr given target = expr<br>
exec("target = expr") or another_expr<br>
<br>
but now we can see how precedence makes a real difference:<br>
<br>
x = 1<br>
x + (exec("x = 50") or x)<br>
<br>
versus:<br>
<br>
x = 1<br>
exec("x = 50) or (x + x)<br>
<br>
<br>
Regardless of which behaviour we choose, some people won't know it and <br>
will have to deal with "difficult mental questions about evaluation <br>
order".<br>
<br>
That's unavoidable, regardless of how we spell it, := or "given". </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
-- <br>
Steve<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
<br>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/CFuqwmE8s-E/unsubscribe" rel="noreferrer" target="_blank">https://groups.google.com/d/topic/python-ideas/CFuqwmE8s-E/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com" target="_blank">python-ideas+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" rel="noreferrer" target="_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div></div>