Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.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; 'syntax': 0.03; 'caller': 0.07; 'lines:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; 'terry': 0.09; 'url:peps': 0.09; 'language': 0.14; 'cases': 0.15; 'properly': 0.15; '"while': 0.16; '3.3.': 0.16; 'complicated,': 0.16; 'correctness': 0.16; 'expr': 0.16; 'iterator': 0.16; 'oct': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'refactored': 0.16; 'simplest': 0.16; 'subject:expression': 0.16; 'yield-from': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'tries': 0.17; 'url:dev': 0.17; 'yield': 0.17; 'jan': 0.18; '>>>': 0.18; 'code.': 0.20; 'equivalent': 0.20; 'issue.': 0.20; 'proposed': 0.20; '3.2': 0.22; 'idea': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'developers': 0.26; 'am,': 0.27; 'opposed': 0.27; 'replace': 0.27; 'header:X-Complaints-To:1': 0.28; 'lines': 0.28; 'allowed,': 0.29; "d'aprano": 0.29; 'steven': 0.29; 'probably': 0.29; 'worked': 0.30; 'sense': 0.31; 'code': 0.31; 'url:python': 0.32; 'not.': 0.32; '+0200,': 0.33; 'cases,': 0.33; 'correctly.': 0.33; 'substantial': 0.33; 'handle': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'version': 0.34; 'adds': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'two': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'some': 0.38; 'things': 0.38; 'possible.': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'address': 0.60; 'range': 0.60; 'save': 0.61; 'first': 0.61; 'thomas': 0.62; 'more': 0.63; 'here': 0.65; 'become': 0.65; 'saving': 0.72; 'transfer': 0.76; 'improvement': 0.84; 'rachel': 0.84; 'received:fios.verizon.net': 0.84; 'power,': 0.91; 'tricky': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: while expression feature proposal Date: Thu, 25 Oct 2012 16:09:20 -0400 References: <50886398.5050301@tim.thechases.com> <20121024222656.GA32708@cskk.homeip.net> <5088779A.3000202@cs.wisc.edu> <5089198d$0$29978$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 In-Reply-To: <5089198d$0$29978$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351195781 news.xs4all.nl 6927 [2001:888:2000:d::a6]:43677 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32158 On 10/25/2012 6:50 AM, Steven D'Aprano wrote: > On Thu, 25 Oct 2012 11:52:31 +0200, Thomas Rachel wrote: > >> Am 25.10.2012 06:50 schrieb Terry Reedy: >> >>> Keep in mind that any new syntax has to be a substantial improvement in >>> some sense or make something new possible. There was no new syntax in >>> 3.2 and very little in 3.3. >> >> I would consinder this at least as new substantial than >> >> yield_from it >> >> as opposed to >> >> for i in it: yield i >> >> - although I think that was a good idea as well. > > Then I think you have misunderstood the purpose of "yield from". The fact > that you can replace the two lines: > > for value in another_iterator: > yield iterator > > with a one-liner "yield from another_iterator" is the least important use- > case for yield-from. If that was the only use-case, it probably would not > have been allowed, because it adds complication to the language for a > trivial gain. > > The purpose of yield-from is to transfer control to another coroutine, > not to save one trivial line of code. > > [quote] > However, if the subgenerator is to interact properly with the caller in > the case of calls to send(), throw() and close(), things become > considerably more difficult. As will be seen later, the necessary code is > very complicated, and it is tricky to handle all the corner cases > correctly. > > A new syntax will be proposed to address this issue. In the simplest use > cases, it will be equivalent to the above for-loop, but it will also > handle the full range of generator behaviour, and allow generator code to > be refactored in a simple and straightforward way. > [end quote] > > http://www.python.org/dev/peps/pep-0380/ > > > "yield from" is a *huge* win in terms of correctness and power, not just > a trivial saving in lines of code. "while expr as var" is not. r = yield from g is equivalent to about 40 lines of code as given here http://www.python.org/dev/peps/pep-0380/#formal-semantics It took the developers several tries to first get a version that worked and then to work out the exact details. -- Terry Jan Reedy