
At 10:55 PM 10/17/03 +0200, Alex Martelli wrote:
while [c for c in [beep()] if c]: boop(c)
..:-).
That is positively *evil*. Good thing you didn't post it on python-list. :)
Anyway, back to the subject, those calls to foo seem very error-prone, while:
foo(x, (yield: y for y in glab for x in blag))
(mandatory extra parentheses, 'yield', and colon) seems far less likely to cause any such error.
And also much uglier. Even though I originally proposed it, I like Guido's version (sans yield) much better. OTOH, I can also see where the "tuple comprehension" and other possible confusing uses seem to shoot it down. Hm. What if list comprehensions returned a "lazy list", that if you took an iterator of it, you'd get a generator-iterator, but if you tried to use it as a list, it would populate itself? Then there'd be no need to ever *not* use a listcomp, and only one syntax would be necessary. More specifically, if all you did with the list was iterate over it, and then throw it away, it would never actually populate itself. The principle drawback to this idea from a semantic viewpoint is that listcomps can be done over expressions that have side-effects. :(