Re: expression in an if statement

2010-08-22 Thread Gregory Ewing
Thomas Jollans wrote: What if set has side effects? A compiler could only exclude this possibility if it knew exactly what set will be at run time, And also that 'a' remains bound to the same object, and that object or anything reachable from it is not mutated in any way that could affect the

Re: expression in an if statement

2010-08-21 Thread alex23
John Nagle na...@animats.com wrote: I was talking to the Facebook guys doing the compiler for PHP, and they said that it was a huge win for them that PHP doesn't allow dynamically replacing a function. I'm not sure if I call all that effort for a 50% speed increase a win. PyPy is seeing speed

Re: expression in an if statement

2010-08-20 Thread John Nagle
On 8/18/2010 3:12 PM, Thomas Jollans wrote: On Wednesday 18 August 2010, it occurred to John Nagle to exclaim: On 8/18/2010 11:24 AM, ernest wrote: Hi, In this code: if set(a).union(b) == set(a): pass Does Python compute set(a) twice? CPython does. Shed Skin might optimize. Don't

Re: expression in an if statement

2010-08-19 Thread Frederic Rentsch
On Thu, 2010-08-19 at 00:12 +0200, Thomas Jollans wrote: On Wednesday 18 August 2010, it occurred to John Nagle to exclaim: On 8/18/2010 11:24 AM, ernest wrote: Hi, In this code: if set(a).union(b) == set(a): pass Does Python compute set(a) twice? CPython does.

Re: expression in an if statement

2010-08-19 Thread ernest
On 19 Ago, 08:40, Frederic Rentsch anthra.nor...@bluewin.ch wrote: On Thu, 2010-08-19 at 00:12 +0200, Thomas Jollans wrote: On Wednesday 18 August 2010, it occurred to John Nagle to exclaim: On 8/18/2010 11:24 AM, ernest wrote: Hi, In this code: if set(a).union(b) == set(a):

expression in an if statement

2010-08-18 Thread ernest
Hi, In this code: if set(a).union(b) == set(a): pass Does Python compute set(a) twice? Thanks in advance. Ernest -- http://mail.python.org/mailman/listinfo/python-list

Re: expression in an if statement

2010-08-18 Thread Peter Otten
ernest wrote: In this code: if set(a).union(b) == set(a): pass Does Python compute set(a) twice? a = abc b = def _set = set def set(x): ... print computing set(%r) % x ... return _set(x) ... if set(a).union(b) == set(a): pass ... computing set('abc') computing set('abc') So

Re: expression in an if statement

2010-08-18 Thread John Nagle
On 8/18/2010 11:24 AM, ernest wrote: Hi, In this code: if set(a).union(b) == set(a): pass Does Python compute set(a) twice? CPython does. Shed Skin might optimize. Don't know about Iron Python. John Nagle --

Re: expression in an if statement

2010-08-18 Thread Thomas Jollans
On Wednesday 18 August 2010, it occurred to John Nagle to exclaim: On 8/18/2010 11:24 AM, ernest wrote: Hi, In this code: if set(a).union(b) == set(a): pass Does Python compute set(a) twice? CPython does. Shed Skin might optimize. Don't know about Iron Python. I doubt

Re: expression in an if statement

2010-08-18 Thread Daniel Kluev
On Thu, Aug 19, 2010 at 9:12 AM, Thomas Jollans tho...@jollybox.de wrote: I doubt any actual Python implementation optimizes this -- how could it? The object set is clearly being called twice, and it happens to be called with the object a as a sole argument twice. What if set has side