scarblac-spamtrap at pino.selwerd.nl
Mon May 1 09:49:15 CEST 2000
Eric Jacobs wrote in comp.lang.python:
> Here's an example to give you an idea of the depth of the problem:
> while i < len(x):
> The expression len(x) looks like a candidate for code motion. That is, we
> would like to move the expression above the loop, computing it once
> instead of redundant computing the same value every time through the loop.
> In order to do that, we must prove that 1) len(x) computes the same value
> every time it is evaluated with the same arguments (it is purely
> functional), and 2) that evaluating len(x) causes no change in the value
> of any expression (it is side-effect free.)
> Firstly, we must check the body of the loop to make sure that no
> assignments are made to x.
There's even more: you need to check for assignment to len in the loop as
Hmm. I think it's impossible in general to check algorithmically if a
function, always given the same argument, always returns the same thing.
(although you can flag the difficult cases and assume they're not purely
functional, I suppose).
Remco Gerlich, scarblac at pino.selwerd.nl
Hi! I'm a .sig virus! Join the fun and copy me into yours!
More information about the Python-list