<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 7 May 2018 at 12:51, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">If any other form of comprehension level name binding does eventually get accepted, then inline scope declarations could similarly be used to hoist values out into the surrounding scope:<br><br></div><div class="gmail_quote">        rem = None<br></div><div class="gmail_quote"><div class="gmail_quote">        while any((nonlocal rem := n % p) for nonlocal p in small_primes):<br></div><div class="gmail_quote">            # p and rem were declared as nonlocal in the nested scope, so our rem and p point to the last bound value<br></div></div></div></div></blockquote><div><br></div><div>Thinking about it a little further, I suspect the parser would reject "nonlocal name := ..." as creating a parsing ambiguity at statement level (where it would conflict with the regular nonlocal declaration statement).<br><br></div><div>The extra keyword in the given clause would avoid that ambiguity problem:<br><br><div class="gmail_quote">        p = rem = None<br></div><div class="gmail_quote"><div class="gmail_quote">        while any(rem for nonlocal p in small_primes given nonlocal rem = n % p):<br></div><div class="gmail_quote">            # p and rem were declared as nonlocal in the nested scope, so our p and rem refer to their last bound values<br><br></div><div class="gmail_quote">Such a feature could also be used to make augmented assignments do something useful at comprehension scope:<br><br></div><div class="gmail_quote">    input_tally = 0<br></div><div class="gmail_quote">    process_inputs(x for x in input_iter given nonlocal input_tally += x)<br></div></div><div class="gmail_quote"></div><div class="gmail_quote"><br></div>Cheers,<br></div><div>Nick.<br></div><div></div></div><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>   |   Brisbane, Australia</div>
</div></div>