frange() question

John J. Lee jjl at pobox.com
Sat Sep 22 14:21:07 EDT 2007


Carsten Haese <carsten at uniqsys.com> writes:

> On Sat, 2007-09-22 at 07:27 +0000, John J. Lee wrote:
>> Carsten Haese <carsten at uniqsys.com> 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.

OK.  There's an obvious second language issue here (the first being
the generator / generator function), which I was trying to draw
attention away from, in the interests of explaining the concept, and
the first language issue.  Probably a bad idea!


> 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.

Seems to me that's a definitional thing, with no conceptual content,
so "difference of opinion" seems an odd choice of words.  It would be
nice to nail the definitions down.  Do the Python docs do that?


> 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.

Ah, they do -- thanks.  Though I'm now left puzzled why you express
your "difference of opionion" above...


John



More information about the Python-list mailing list