On Sat, 2007-09-22 at 07:27 +0000, John J. Lee wrote: > Carsten Haese <[EMAIL PROTECTED]> writes: > > > On Thu, 2007-09-20 at 18:55 +0000, John J. Lee wrote: > >> Functions are never generators, senso stricto. There are "generator > >> functions", which *return* (or yield) generators when you call them. > > > > Actually, a generator function is a function that returns a generator. > > Read what I wrote again. What makes you begin your sentence with > "Actually", rather than "Putting it another way"?
I was attempting to correct your interjection "(or yield)." A generator function doesn't yield a generator; it returns a generator that yields sequence values. The second half of my post illustrates a difference of opinion about what constitutes a generator function. You state that frange() is not a generator function because it doesn't use yield, but it behaves like one. My point is that it *is* a generator function because the generator expression is merely syntactic sugar for an equivalent for/yield loop. Of course, the distinction of whether frange() *is* a generator function or merely *behaves* as one is immaterial in practice, and we can both be right in the absence of a formal definition of what a generator function is. PEP 255 says "A function that contains a yield statement is called a generator function," but that was written before generator expressions were introduced. HTH, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list