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


Groups > comp.lang.python > #51757

Re: Oddity with 'yield' as expression - parentheses demanded

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.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.04; 'say,': 0.05; 'assignment': 0.07; 'expressions': 0.07; "subject:' ": 0.07; 'adopted': 0.09; 'consistency': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'jan': 0.12; '(x,': 0.16; 'bind': 0.16; 'brackets:': 0.16; 'comma.': 0.16; 'discarded.': 0.16; 'expression,': 0.16; 'expression.': 0.16; 'governed': 0.16; 'preserve': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'return,': 0.16; 'semantically': 0.16; 'subject:expression': 0.16; 'subject:yield': 0.16; 'tuple': 0.16; 'wrote:': 0.18; '(not': 0.18; 'basically': 0.19; 'normally': 0.19; 'thu,': 0.19; 'meant': 0.20; '(in': 0.22; 'aug': 0.22; 'rules': 0.22; 'header:User-Agent:1': 0.23; 'right.': 0.26; 'primary': 0.26; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; 'statement': 0.30; '(which': 0.31; 'equivalent.': 0.31; 'subject:with': 0.35; 'created': 0.35; 'except': 0.35; 'there': 0.35; 'yield': 0.36; 'should': 0.36; 'being': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'expression': 0.60; 'ian': 0.60; 'received:173': 0.61; 'became': 0.64; 'places': 0.64; 'more': 0.64; 'is)': 0.84; 'received:fios.verizon.net': 0.84; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Oddity with 'yield' as expression - parentheses demanded
Date Thu, 01 Aug 2013 15:25:28 -0400
References <CAPTjJmoCj40Gbktu-0Tkos_toTWvPJ8_0r61FC9wU0GA9gMDMw@mail.gmail.com> <CALwzidm=afnn=nHgzp9Ru=7eJQmH=zE8JGX+-9O2k8SAYfdvUw@mail.gmail.com> <CAPTjJmpQm3bne0YL3jwXYFEZLavTOeBbb008-XcK7Min1W-5mg@mail.gmail.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:17.0) Gecko/20130620 Thunderbird/17.0.7
In-Reply-To <CAPTjJmpQm3bne0YL3jwXYFEZLavTOeBbb008-XcK7Min1W-5mg@mail.gmail.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.91.1375385141.1251.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375385141 news.xs4all.nl 15945 [2001:888:2000:d::a6]:45084
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51757

Show key headers only | View raw


On 8/1/2013 1:58 PM, Chris Angelico wrote:
> On Thu, Aug 1, 2013 at 6:35 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> yield was a statement before it became an expression, and the syntax
>> "yield x, y, z" was (and still is) perfectly legal, with all three
>> expressions (technically a single tuple expression) being governed by
>> the yield.  That is to say, "yield x, y, z" and "yield (x, y, z)" are
>> semantically equivalent.  When it became an expression, in order to
>> preserve this equivalence, that meant that the yield expression needed
>> to bind even less tightly than the comma.  In terms of the grammar,
>> yield needed to take an expression_list, not just an expression.
>>
>> There are only three places in the grammar where expression_lists are
>> used without enclosing them in brackets:  expression statements (in
>> this case analogous to the yield statement), the return statement (not
>> normally used to return a value in a generator), and the assignment
>> statements.  So for consistency and clarity the rules for
>> parenthesizing yield statements are basically adopted from the
>> existing rules for parenthesizing expression_lists.
>
> Ahh, right. That makes good sense.
>
> If this were being created anew now, would yield be made to bind more
> tightly than the comma?

As a statement (which is the primary use of yield), yield is like 
return, except that the execution frame is not discarded. So I think it 
should bind like return, which is very loosely.


-- 
Terry Jan Reedy

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


Thread

Re: Oddity with 'yield' as expression - parentheses demanded Terry Reedy <tjreedy@udel.edu> - 2013-08-01 15:25 -0400

csiph-web