Steve Howell showell30 at
Fri Jun 1 14:31:43 CEST 2007

--- Tijs <tijs_news at> wrote:

> Steve Howell wrote:
> > FWIW there's the possibility that even without a
> > subexpression syntax, some Python implementations
> > would detect the duplication of x*x and optimize
> that
> > for you.  It would have to know that x*x had no
> side
> > effects, which I think is a safe assumption even
> in a
> > dynamic language like Python.
> No, x may be an object that has the __mul__ special
> method, and it may have
> side effects. 

Ok, I stand corrected.

Duplicate subexpressions are pretty easy to avoid in
Python, so though an optimization would not be
impossible here (checking for immutability of
builtins, etc., which still assumes the idea that
multiplication is more expensive than checking for
immutability even for the common builtin case), it
would not be worthwhile.

Shortly after I posted, there was an elegant solution
to avoiding having to repeat x*x in the lambda, so the
point's kind of moot now.

Shape Yahoo! in your own image.  Join our Network Research Panel today! 

More information about the Python-list mailing list