functional vs procedural list comprehension

Chris Barker chrishbarker at home.net
Fri Sep 7 19:13:43 EDT 2001


Tim Peters wrote:
> > I would be interested in the reasons for the procedural choice and
> > arguments for functional vs procedural behavior.
 
> I wouldn't.  If somebody wants faster listcomps, don't argue about it,
> implement it.  If it actually has a killer speed advantage, have faith that
> Guido will rationalize away any change in semantics <wink> -- but first be
> sure there actually is a killer speed advantage.

I would. because:

A) it's not just speed, it would makes a difference for code clarity as
well. The question is whether the current approach was chosen for
language design reasons, or because it was easy to impliment that way.

B) There may have been some very good reasons for the choice that would
save a lot of work... There a number of things that could speed up
Python a lot if you were to change Python's semantics... but as many
have said, you'd have a faster language, but it wouldn't be Python. 

C) I think that is one of the problems with getting perfomance into
Python: it's kind of a chicken-egg thing: show me the performance, and
we'll make the change, but you can't really get the performance unless
the change is made. In a case like this, I think the real gain could
come if you had homogenous sequences and a JIT compiler...That's a heck
of project, and it won't come to be until it is way too late (if
ever...) to change the semantics of list comprehensions: it is very
clear that anything that changes the symantics of the language is in for
a hard fight.

D) We already know one potential speed advantage: the original reason
for this thread was because I wanted to know why map() was faster than
list comprehensions for the same thing. The reason is that it is
esentially implimented internally as a nested for loop. Because, as
Peter puts it, a "procedural" approach was chosen, rather than a
"functional" one, it has to stay that way: the loops could not be put
into C. We know what we could gain from changing that. We also know we
would lose something. Is the dynamicism lost something that people
really think they would use often enough that for loops wouldn't satisfy
them?


E) Frankly, I don't think is is going to change anyway, and I have no
intention of making an effort to change it, but in my effort to
understand Python and language design, I'd like to know what when into
that decision. Was this issue even brought up when list comprehensions
were being discussed??


-Chris











-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list