On Sunday, March 15, 2015 at 1:45:37 AM UTC+5:30, Ian wrote: > Now which should be considered definitive, the language reference or > the PEP? This question is not rhetorical; I don't know the answer. > Regardless of the answer though, the PEP at least illuminates the > design intent of the terminology. > > > [1] https://docs.python.org/3/reference/expressions.html#yield-expressions > > [2] https://www.python.org/dev/peps/pep-0255/
Thanks That PEP deserves careful reading, particularly the end... | BDFL Pronouncements | Issue: Introduce another new keyword (say, "gen" or "generator") in | place of "def", or otherwise alter the syntax, to distinguish | generator-functions from non-generator functions. | | Con: In practice (how you think about them), generators *are* | functions, but with the twist that they're resumable. The mechanics of | how they're set up is a comparatively minor technical issue, and | introducing a new keyword would unhelpfully overemphasize the | mechanics of how generators get started (a vital but tiny part of a | generator's life). | | Pro: In reality (how you think about them), generator-functions are | actually factory functions that produce generator-iterators as if by | magic. In this respect they're radically different from non-generator | functions, acting more like a constructor than a function, so reusing | "def" is at best confusing. A "yield" statement buried in the body is | not enough warning that the semantics are so different. | | BDFL: "def" it stays. No argument on either side is totally | convincing, so I have consulted my language designer's intuition. It | tells me that the syntax proposed in the PEP is exactly right - not too | hot, not too cold. But, like the Oracle at Delphi in Greek mythology, | it doesn't tell me why, so I don't have a rebuttal for the arguments | against the PEP syntax. The best I can come up with (apart from | agreeing with the rebuttals ... already made) is "FUD". If this had | been part of the language from day one, I very much doubt it would have | made Andrew Kuchling's "Python Warts" page. So while I dont go to the extent of suggesting introducing a different keyword for generators, the fact that the overloading of def is problematic and arbitrary comes from the horse's (ie BDFL's) mouth. -- https://mail.python.org/mailman/listinfo/python-list