Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: while expression feature proposal (http://www.velocityreviews.com/forums/t953942-re-while-expression-feature-proposal.html)

 Cameron Simpson 10-26-2012 11:56 PM

Re: while expression feature proposal

On 26Oct2012 19:41, Devin Jeanpierre <jeanpierreda@gmail.com> wrote:
| On Fri, Oct 26, 2012 at 6:03 PM, Cameron Simpson <cs@zip.com.au> 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/exp...aluation-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 <cs@zip.com.au>

Acceptance Testing: Dropping your mods straight into the production
environment to see if the users will accept them.

 All times are GMT. The time now is 05:58 PM.