
On Fri, Nov 21, 2014 at 9:41 AM, Antony Lee antony.lee@berkeley.edu wrote:
I would like to believe that "break"-as-a-expression solves most of these issues. It is reasonable, though, to drop the "return"-as-an-expression part of the proposal, because you need to know that the comprehension is run in a separate function to understand it (it's a bit ironic that I am dropping the original proposal to defend my own, now...).
Consider
((x, y) for x in l1 if f1(x) or break for y in l2 if f2(y) or break)
This maps directly to
for x in l1: if f1(x) or break: for y in l2: if f2(y) or break: yield x, y
which is literally a copy-paste of the second part followed by yielding the first part. I think this reads reasonably well but this is obviously a subjective issue.
I really hope "or break" doesn't become an idiom if break is turned into an expression. I find [x if x < N else break for x in ...] so much more readable than [x for x in ... if x < N or break]
This is very near (but not directly equivalent) to the relatively idiomatic:
for x in ...: if x < N: yield x else: break
-- Devin