<div dir="ltr">On Mon, Jul 1, 2013 at 10:25 AM, Joshua Landau <span dir="ltr"><<a href="mailto:joshua.landau.ws@gmail.com" target="_blank">joshua.landau.ws@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>> primes100 = {p for p in primes(); break if p >= 100}<br>
> primes100 = {p for p in primes() while p < 100}<br>
<br>
</div>If you're telling me that "{p for p in primes() while p < 100}" reads<br>
better than "{p for p in primes(); break if p >= 100}" I have to<br>
disagree strongly. The "break if" form looks beautiful.<br></blockquote><div><br></div><div>My own taste is in strong contrast to Joshua's.  I think the semi-colon/break-if looks absolutely horrendous and ugly.  The 'while' clause looks obvious, beautiful, and intuitive.<br>

<br>However, I see the point made by a number of people that the 'while' clause has no straightforward translation into an unrolled loop, and is probably ruled out on that basis.  <br><br></div><div>That said, I think the version using Guido's suggestion (and already supported for generator comprehensions) looks fairly nice.  I.e. given a support function:<br>
</div><div><br>  def stopif(x):<br>      if x: raise StopIteration<br>
      return True<br><br></div><div>We can express it as:<br><br></div><div>  primes100 = set(p for p in primes() if stopif(p >= 100))<br><br></div><div>Except I'm not sure I like the spelling of 'stopif()', since the repeating the 'if' in the function name reads oddly.  I guess I might like this spelling better:<br>
<br></div><div>  primes100 = set(p for p in primes() if still(p < 100))  # Obvious implementation of still()<br></div><div><br></div><div>The only change we need is the one Guido has declared as "do it" which is to make other comprehensions act the same as the instantiation with the generator.  I.e. this should work:<br>
<br></div><div>  primes100 = {p for p in primes() if still(p < 100)}<br></div><div> <br></div><div>It doesn't *really* matter whether someone likes my spelling 'still()' or Guido's 'stopif()' better, since either one is trivially implementable by end users if they wish to do so.<br>
</div></div><br>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>
advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br>
</div></div>