yield expression programmized-formal interpretation. (interpretationof yield expression.)

Discussion in 'Python' started by castironpi@gmail.com, Apr 21, 2008.

  1. Guest

    What if I say

    oath= yield

    or

    other= yield

    ?

    Does yield evaluate without parenthes? (Eth.)
     
    , Apr 21, 2008
    #1
    1. Advertisements

  2. Re: yield expression programmized-formal interpretation.(interpretation of yield expression.)

    En Mon, 21 Apr 2008 15:03:05 -0300, <> escribió:

    > What if I say
    >
    > oath= yield
    >
    > or
    >
    > other= yield
    >
    > ?
    >
    > Does yield evaluate without parenthes? (Eth.)


    You can't use yield except in a generator function. From
    <http://docs.python.org/ref/yieldexpr.html> and the grammar definition at
    <http://docs.python.org/ref/grammar.txt> you can see that

    assignment_stmt ::=
    (target_list "=")+
    (expression_list | yield_expression)

    yield_expression ::= "yield" [expression_list]

    The last expression_list is optional so a bare yield should be allowed in
    the right hand side of an assignment, as if it were `yield None` (I think
    such behavior is specified in the original PEP). Let's try:

    py> def gen():
    .... x = yield
    .... y = yield "second"
    .... yield x, y
    ....
    py> g = gen()
    py> print g.next()
    None
    py> print g.send(123)
    second
    py> print g.send(456)
    (123, 456)
    py> print g.send(789)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    StopIteration

    --
    Gabriel Genellina
     
    Gabriel Genellina, Apr 22, 2008
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wallclimber
    Replies:
    3
    Views:
    688
    Wallclimber
    May 26, 2004
  2. tomer
    Replies:
    0
    Views:
    2,775
    tomer
    Jul 28, 2011
  3. Markus
    Replies:
    1
    Views:
    383
    Mark Hubbart
    Sep 27, 2004
  4. Michael Edgar
    Replies:
    13
    Views:
    470
    Brian Candler
    Apr 21, 2011
  5. Ziliang Chen

    yield expression

    Ziliang Chen, Feb 25, 2013, in forum: Python
    Replies:
    7
    Views:
    277
    Dave Angel
    Feb 27, 2013
  6. Ziliang Chen

    yield expression

    Ziliang Chen, Feb 25, 2013, in forum: Python
    Replies:
    3
    Views:
    192
    Ziliang Chen
    Feb 25, 2013
  7. Ziliang Chen

    yield expression

    Ziliang Chen, Feb 25, 2013, in forum: Python
    Replies:
    0
    Views:
    167
    Ziliang Chen
    Feb 25, 2013
  8. Chris Angelico
    Replies:
    0
    Views:
    144
    Chris Angelico
    Aug 1, 2013
Loading...