On Thu, Nov 20, 2014 at 4:36 PM, Chris Angelico <rosuav@gmail.com> wrote:
On Fri, Nov 21, 2014 at 3:21 AM, Nick Coghlan <ncoghlan@gmail.com> wrote:
That does also suggest another possible alternative to the "or stop()" trick - allow *break* as an expression.
Or just as a keyword component of a comprehension, in the same way 'for' is. Since 'if' already has meaning, [x for x in range(10) if x
= 5 break] would be confusing, so probably it'd have to be the slightly-awkward-to-read [x for x in range(10) break x >= 5], adding a termination condition to the preceding loop.
'break' is certainly better than 'return' -- currently 'break' means "look for the nearest enclosing loop", not "look for the enclosing function", so it'd preserve that at least. [x for x in range(10) if x >= 5 else break]? with 'else break' handled in the grammar as a non-compositional phrase like 'is not'? Not sure how this interacts with multiple mixed for and if clauses -- I've never wrapped my head around those semantics. -n -- Nathaniel J. Smith Postdoctoral researcher - Informatics - University of Edinburgh http://vorpus.org