functional vs procedural list comprehension

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sat Sep 8 12:30:05 CEST 2001


Fri, 07 Sep 2001 16:13:43 -0700, Chris Barker <chrishbarker at home.net> pisze:

> 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.

It's because it's easier to design the language that way.

There is no real purpose why map(str, l) should be different than
[str(x) for x in l] wrt. the time of getting the binding of str,
considering their usages.

It follows from facts that functions bound to names are passed like
other objects, that a list comprehension includes an expression
evaluated many times, and that most names are mutable.

You can't easily change any of these decisions. They follow from
what "evaluate an expression" means (which includes getting objects
bound to names used in it), how Python passes objects to functions,
and how name bindings are created.

It's not an artifact of the implementation. It's an artifact of the
language design.

Which element would you change? For example how would you want to
change the meaning of list comprehensions? In particular when
    x[0] or spam
would get the object bound to the name spam, where x is the object
taken from the list?

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list