Why functional Python matters

Dave Benjamin ramen at lackingtalent.com
Thu Apr 24 03:04:41 EDT 2003


In article <mailman.1051154381.32098.python-list at python.org>, Tim Peters wrote:
> (Python statements are not Python expressions, so no
> matter how perverse you try to be, you can't write a Python lambda that
> contains a Python statement -- what you can do inside a Python lambda is use
> a crippled subset of the language).

This is what I was talking about in my original post. I don't believe that
the Python lambda offers a crippled subset of the language any more than I
believe that a constant offers a crippled subset of the functionality of a
variable. Lambdas are expressions, for use with other expressions. Defs
are statements, for use with other statements. I don't find this crippled or
redundant.

Perhaps this is an over-generalization, but I think that nestability
encourages readability. The nice thing about lambdas in Python are that they
enforce this property.

> That said, Guido regrets lambdas anyway <wink>.

He may one day live to regret regretting lambdas. =) In the meantime, all
I'm saying is that I really like Python the way it is. Why ruin a good thing?

One last thing and I'm off of my soapbox. ;) I've been thinking more about
the parallel between list comprehensions and relational calculus vs.
map/filter functions and relational algebra. I mentioned this briefly before
but I want to bring it up again because nobody commented. I'm totally open
to criticism. Nonetheless, did anybody notice that filter+lambda can express
a "select" operation in relational algebra using almost identical syntax:

r.a.: select [age > 20] (people)
python: filter(lambda x: x.age > 20, people)

Now, most of the time, perhaps we use a form of relational calculus (SQL) to
do this type of thing anyway. But relational algebra is still around. It's
still a useful concept. Why?

 1. It's very regular
 2. It's easy to parse
 3. It's very portable across languages
 
I can port my map/filter code to PHP, for instance, or to LISP, or even to
ActionScript (with appropriate language hacks). List comprehensions, on the
other hand, are proprietary Python (or Haskell) extensions from a
meta-linguistic perspective. I love them to death, still, but just think
about it.

Okay, I'm off to meta-land. 'Night, y'all. =)
Peac,
Dave




More information about the Python-list mailing list