Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'implied,': 0.09; 'subject:while': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '_do_': 0.16; 'dropping': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'lexical': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'oct': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:edu.au': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'simpson': 0.16; 'subject:expression': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'define': 0.20; 'defined': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'example': 0.23; 'this:': 0.23; 'second': 0.24; 'so.': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'first,': 0.27; 'right.': 0.27; 'separate': 0.27; 'environment': 0.29; 'acceptance': 0.29; 'skip:_ 10': 0.29; 'evaluation': 0.30; 'fri,': 0.30; 'function': 0.30; 'url:python': 0.32; 'clear': 0.35; 'pm,': 0.35; 'but': 0.36; 'url:org': 0.36; 'received:au': 0.36; 'should': 0.36; 'charset:us- ascii': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'there,': 0.38; 'your': 0.60; 'content-disposition:inline': 0.60; 'side': 0.61; 'free': 0.61; 'production': 0.63; '26,': 0.65; 'special': 0.73; 'hand': 0.82; 'evaluation.': 0.84; 'url:reference': 0.84; 'effects.': 0.91 Date: Sat, 27 Oct 2012 10:56:01 +1100 From: Cameron Simpson To: Devin Jeanpierre Subject: Re: while expression feature proposal MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) References: Cc: "comp.lang.python" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351295765 news.xs4all.nl 6846 [2001:888:2000:d::a6]:53146 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32247 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.