Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32158

Re: while expression feature proposal

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 <python-python-list@m.gmane.org>
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 <tjreedy@udel.edu>
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> <mailman.2811.1351140683.27098.python-list@python.org> <k6b257$l8k$1@r03.glglgl.gl> <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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2862.1351195781.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: while expression feature proposal Terry Reedy <tjreedy@udel.edu> - 2012-10-25 00:50 -0400
  Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 11:52 +0200
    Re: while expression feature proposal Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-25 10:50 +0000
      Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 13:20 +0200
      Re: while expression feature proposal Terry Reedy <tjreedy@udel.edu> - 2012-10-25 16:09 -0400
    Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-25 10:44 -0600
  Re: while expression feature proposal Grant Edwards <invalid@invalid.invalid> - 2012-10-25 14:17 +0000

csiph-web