Re: while expression feature proposal

Discussion in 'Python' started by Cameron Simpson, Oct 27, 2012.

  1. On 26Oct2012 19:41, Devin Jeanpierre <> wrote:
    | On Fri, Oct 26, 2012 at 6:03 PM, Cameron Simpson <> wrote:
    | > Any doco would need to make it clear that no order of operation is
    | > implied, so that this:
    | >
    | > x = 1
    | > y = (2 as x) + x
    | >
    | > does not have a defined answer; might be 2, might be 3. Just like any
    | > other function call with side effects.
    |
    | But function calls with side effects _do_ have a defined order of
    | evaluation. Left to right.
    | And the answer should be 4.
    | http://docs.python.org/reference/expressions.html#evaluation-order

    No. Separate _expressions_ are evaluated left to right.

    So this:

    f(1), f(2)

    calls "f(1)" first, then "f(2)". But this:

    f(1) + f(2)

    need not do so. Counter-documentation welcomed, but the doco you cite
    does not define an order for the second example above.

    |
    | >>> def set_(d, k, v):
    | ... d[k] = v
    | ... return v
    | ...
    | >>> d = {}
    | >>> set_(d, 'x', 1)
    | 1
    | >>> set_(d, 'y', set_(d, 'x', 2) + d['x'])
    | 4

    That may just be a coincidence of implementation - there's no special
    reason to change the evaluation order form the lexical order there, but
    expression optimisers should have a free hand generally.

    Cheers,
    --
    Cameron Simpson <>

    Acceptance Testing: Dropping your mods straight into the production
    environment to see if the users will accept them.
     
    Cameron Simpson, Oct 27, 2012
    #1
    1. Advertising

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. Dan Loewenherz

    while expression feature proposal

    Dan Loewenherz, Oct 24, 2012, in forum: Python
    Replies:
    1
    Views:
    152
    Paul Rubin
    Oct 24, 2012
  2. Ian Kelly
    Replies:
    0
    Views:
    141
    Ian Kelly
    Oct 24, 2012
  3. Tim Chase
    Replies:
    0
    Views:
    159
    Tim Chase
    Oct 24, 2012
  4. Cameron Simpson

    Re: while expression feature proposal

    Cameron Simpson, Oct 24, 2012, in forum: Python
    Replies:
    6
    Views:
    173
    Thomas Rachel
    Oct 25, 2012
  5. Chris Angelico

    Re: while expression feature proposal

    Chris Angelico, Oct 24, 2012, in forum: Python
    Replies:
    0
    Views:
    188
    Chris Angelico
    Oct 24, 2012
Loading...

Share This Page