functional vs procedural list comprehension

Guido van Rossum guido at python.org
Sun Sep 9 01:26:47 EDT 2001


> I would be interested in the reasons for the procedural choice and
> arguments for functional vs procedural behavior.

Consistency, both in semantics and implementation.  It's easier to
explain that [<expr> for ...] evaluates <expr> each time through the
loop than it would be to explain that <expr> is analyzed at compile
time and all its bindings frozen the first time it is evaluated.  It's
also easier to implement, because that kind of analysis is not done
anywhere else in the bytecode compiler.

Someone remarked that the functional behavior would be easier to
understand; I think that's only true if you know a whole lot about
compilers and functional languages.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list