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

Re: expression in an if statement

2010-08-20 Thread alex23
John Nagle 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 increases of up

Re: expression in an if statement

2010-08-19 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 kn

Re: expression in an if statement

2010-08-19 Thread ernest
On 19 Ago, 08:40, Frederic Rentsch 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): pass >

Re: expression in an if statement

2010-08-18 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?

Re: expression in an if statement

2010-08-18 Thread Daniel Kluev
On Thu, Aug 19, 2010 at 9:12 AM, Thomas Jollans 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 effects? A > c

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

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 -- http://mail.python.org/mailman/listinf

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')