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

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Oddity with 'yield' as expression - parentheses demanded
Date 2013-08-01 15:25 -0400
References <CAPTjJmoCj40Gbktu-0Tkos_toTWvPJ8_0r61FC9wU0GA9gMDMw@mail.gmail.com> <CALwzidm=afnn=nHgzp9Ru=7eJQmH=zE8JGX+-9O2k8SAYfdvUw@mail.gmail.com> <CAPTjJmpQm3bne0YL3jwXYFEZLavTOeBbb008-XcK7Min1W-5mg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.91.1375385141.1251.python-list@python.org> (permalink)

Show all headers | 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