On Friday 17 October 2003 08:57 pm, Skip Montanaro wrote: ... > Forgive my extreme density on this matter, but I don't understand what > > (yield x for x in S) > > is supposed to do. Is it supposed to return a generator function which I > can assign to a variable (or pass to the builtin function sum() as in your > example) and call later, or is it supposed to turn the current function > into a generator function (so that each executed yield statement returns a > value to the caller of the current function)? Neither: it returns an iterator, _equivalent_ to the one that would be returned by _calling_ a generator such as def xxx(): for x in S: yield x like xxx() [the result of the CALL to xxx, as opposed to xxx itself], (yield: x for x in S) is not callable; rather, it's loopable-on. > you don't like lambda, I can't quite see why syntax this is all that > appealing. I don't really like the current state of lambda (and it will likely never get any better), I particularly don't like the use of the letter lambda for this idea (Church's work notwithstanding, even Paul Graham in his new lispoid language has chosen a more sensible keyword, 'func' I believe), but I like comprehensions AND iterators, and the use of the word yield in generators. I'm not quite sure what parallels you see between the two cases. Alex
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