Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'programmer': 0.03; 'source,': 0.04; 'argument': 0.05; 'retrieved': 0.05; '"""': 0.07; 'variables': 0.07; '*is*': 0.09; '[1]:': 0.09; '[2]:': 0.09; 'arguments': 0.09; 'pep': 0.09; 'processing,': 0.09; 'statements': 0.09; 'python': 0.11; 'language.': 0.14; '255': 0.16; 'called,': 0.16; 'definition.': 0.16; 'entry:': 0.16; 'executed.': 0.16; 'generator.': 0.16; 'iterator': 0.16; 'iterator,': 0.16; 'iterators': 0.16; 'justified': 0.16; 'programmers.': 0.16; 'resumes,': 0.16; 'returned;': 0.16; 'subject:generator': 0.16; 'url:peps': 0.16; 'usable': 0.16; 'sat,': 0.16; 'all.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'producing': 0.19; '>>>': 0.22; '(in': 0.22; 'error': 0.23; 'precise': 0.24; 'url:dev': 0.24; 'regardless': 0.24; 'looks': 0.24; 'question': 0.24; 'source': 0.25; 'mention': 0.26; 'pending': 0.26; 'least': 0.26; 'subject:/': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; '[1]': 0.29; 'am,': 0.29; '[2]': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'went': 0.31; 'code': 0.31; 'context,': 0.31; "d'aprano": 0.31; 'omitted': 0.31; 'steven': 0.31; 'regular': 0.32; 'quite': 0.32; '(including': 0.33; 'says': 0.33; 'url:python': 0.33; 'alone': 0.33; 'actual': 0.34; 'except': 0.35; 'definition': 0.35; 'usual': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; 'returning': 0.36; 'yield': 0.36; 'entry': 0.36; 'url:org': 0.36; 'should': 0.36; 'clear': 0.37; 'to:addr:python- list': 0.38; 'fact': 0.38; 'though,': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'above,': 0.60; 'temporarily': 0.60; 'full': 0.61; 'url:3': 0.61; 'discuss': 0.62; 'name': 0.63; 'refer': 0.63; 'more': 0.64; 'series': 0.66; 'mar': 0.68; 'natural': 0.68; 'answer.': 0.68; '2015': 0.84; 'entry,': 0.84; 'protocol,': 0.84; 'remembering': 0.84; 'url:reference': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=dR9k8+JBZ29AGVsjSM+9AlvcSBPZeQrLQZu34h/sRWQ=; b=TnmO3pJo4UFbN4Kn++hLiDfP1eqcMwUCNTRBglKasWWIcmiSd+UpmPB4FvS8FLVGuj 8RSTtGNVCzzn2PzxVQzg56sIh93OkHP4GjL/Qy/RQUa5I6hRfCqpEG4tXEuDxpgVBHtC 960+i8sIpMIKRkmOom51J268XZK7u6k854x4RQQ8laItTA8c4Sz4bHUT6D9Z3zU3Okg1 UBnSeo2UZ+CqXO9fRQ/+4uPukJTKcChVZyTbD81/WVGjf1gkDv09+0HuSf3X4+kGEC95 dr7/uFzLp/VK/AjIho/NtcfZrko1Td1Q/O5nWyLaISue0JVFHHZl5sNeY2Kuk6fbNxUe n4xQ== X-Received: by 10.70.138.69 with SMTP id qo5mr39634702pdb.124.1426364115545; Sat, 14 Mar 2015 13:15:15 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <87zj7govya.fsf@elektro.pacujo.net> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <87twxqqewm.fsf@elektro.pacujo.net> <4eec1709-dd11-4891-bfcc-60b27bb00ee3@googlegroups.com> <550259bf$0$12975$c3e8da3$5496439d@news.astraweb.com> <00d9152a-f391-4c64-b2bd-52bdec2a6b67@googlegroups.com> <8761a5s0he.fsf@elektro.pacujo.net> <5503cf5f$0$12985$c3e8da3$5496439d@news.astraweb.com> <87zj7govya.fsf@elektro.pacujo.net> From: Ian Kelly Date: Sat, 14 Mar 2015 14:14:35 -0600 Subject: Re: generator/coroutine terminology To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 80 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1426364119 news.xs4all.nl 2972 [2001:888:2000:d::a6]:42486 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87445 On Sat, Mar 14, 2015 at 1:54 AM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>> Your 'factory' is a: >>> >>> generator >>> A function which returns an iterator. >>> >> >> That glossary entry is misleading, or at least incomplete, and it >> fails to match the way "generator" is used by actual Python >> programmers. > > I am an actual Python programmer (I develop Python programs) and my > definitive source for Python is the documentation. If there is an error > in the documentation, I would very much like it to be corrected. I think that Steven was basing his statement on the definition you cited. I don't think that he actually went and looked up the definition. If he had, he would have seen that you omitted 90% of it. Here's the full entry: """ A function which returns an iterator. It looks like a normal function except that it contains yield statements for producing a series of values usable in a for-loop or that can be retrieved one at a time with the next() function. Each yield temporarily suspends processing, remembering the location execution state (including local variables and pending try-statements). When the generator resumes, it picks-up where it left-off (in contrast to functions which start fresh on every invocation). """ >> A generator (function) may be a function which returns an iterator, >> but not all functions that return iterators are generators, and in >> some ways returning an iterator is the *least* interesting part of >> what makes a generator a generator. >> >> What distinguishes a generator from a regular function is the use of >> `yield`. Any definition which fails to mention that fact is useless. As can be seen above, the glossary definition *does* in fact discuss the use of yield. > The language reference had better use more precise language. It *is* the > definitive source, after all. Okay, but you cited the glossary entry, not the language reference. The language reference says this [1]: "When a generator function is called, it returns an iterator known as a generator." Which I think is quite clear, although to be fair the same section also uses "generator" alone to refer to the function in the preceding paragraph. That usage however is justified by PEP 255 [2]: """ When a generator function is called, the actual arguments are bound to function-local formal argument names in the usual way, but no code in the body of the function is executed. Instead a generator-iterator object is returned; this conforms to the iterator protocol, so in particular can be used in for-loops in a natural way. Note that when the intent is clear from context, the unqualified name "generator" may be used to refer either to a generator-function or a generator-iterator. """ 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/