Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32247 > unrolled thread
| Started by | Cameron Simpson <cs@zip.com.au> |
|---|---|
| First post | 2012-10-27 10:56 +1100 |
| Last post | 2012-10-27 10:56 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: while expression feature proposal Cameron Simpson <cs@zip.com.au> - 2012-10-27 10:56 +1100
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2012-10-27 10:56 +1100 |
| Subject | Re: while expression feature proposal |
| Message-ID | <mailman.2918.1351295765.27098.python-list@python.org> |
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/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 <cs@zip.com.au>
Acceptance Testing: Dropping your mods straight into the production
environment to see if the users will accept them.
Back to top | Article view | comp.lang.python
csiph-web