At 09:10 PM 10/17/03 -0400, Raymond Hettinger wrote: >[GvR] > > I'd just like to pipe into this discussion saying that while Peter > > Norvig's pre-PEP is neat, I'd reject it if it were a PEP; the main > > reason that the proposed notation doesn't return a list. I agree that > > having generator comprehensions would be a more general solution. I > > don't have a proposal for generator comprehension syntax though, and > > [yield ...] has the same problem. > >Is Phil's syntax acceptable to everyone? > > (yield: x*x for x in roots) Ironically, I'm opposed. :) * Yield is a control flow statement, this is an expression * yield: looks like lambda, and this is not a function * Yield only makes sense if you come into this thinking about generators * Yield distracts from the purpose of the expression To put it another way, Python is "executable pseudocode". Listcomps are pseudocode. Yield in a generator is pseudocode. (x*x for x in roots) is pseudocode. But (yield: x*x for x in roots) looks like some kind of weird programming language gibberish. :) I think the worst misinterpretation I could have about the yield-less syntax is that I might think it was a "tuple comprehension" or something that returned a sequence instead of an iterator. However, I'll find out it's not a sequence or tuple if I try to do anything with it that requires a sequence or tuple. My worst case problem is re-execution of the iterator. Which, by the way, brings up a question: should iterator comps be reiterable? I don't see any reason right now why they shouldn't be, and can think of situations where reiterability would be useful.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4