A shame from:comp.lang.python removing lambda, map, filter and reduce

155 views
Skip to first unread message

Steve

unread,
Jul 6, 2005, 12:30:02 PM7/6/05
to
Comrades,

During our current discussion of the fate of functional constructs in
python, someone brought up Guido's bull on the matter:

http://www.artima.com/weblogs/viewpost.jsp?thread=98196

He says he's going to dispose of map, filter, reduce and lambda. He's
going to give us product, any and all, though, which is nice of him.

What really struck me, though, is the last line of the abstract:

"I expect tons of disagreement in the feedback, all from
ex-Lisp-or-Scheme
folks. :-)"

I disagree strongly with Guido's proposals, and i am not an ex-Lisp,
-Scheme or -any-other-functional-language programmer; my only other
real
language is Java. I wonder if i'm an outlier.

So, if you're a pythonista who loves map and lambda, and disagrees with
Guido, what's your background? Functional or not?

tom

--
Batman always wins

Pascal Costanza

unread,
Jul 6, 2005, 1:18:21 PM7/6/05
to

I am not a pythonista, but you posted in comp.lang.lisp, so here I go
anyway.

Before my switch to Lisp, I have been a Java hacker. In Java, you have
lambda, although it's not directly recognizable. For example, if you
implement your own list class, you can add hooks to do get similar effects:

interface Exec {
void exec(Object);
}

class MyList {
Object[] contents;
void mapc(Exec lambda) {
for (int i=0; i < contents.lenght; i++)
lambda.exec(contents[i]);
}
}

MyList l = ...;

l.mapc(new Exec() {
void exec(Object) {
System.out.println(Object);
}});

This is a damn lot to type (and not general enough yet), but you don't
realize this as a Java programmer because you have to type quite a lot
anyway. So anonymous inner classes play the role of closures in Java.

The real problem is not whether Guido is going to remove lambda or not,
the real problem is that Python (as most other languages) don't provide
you enough abstraction mechanisms to get around language limitations.
Assume you didn't have lambda in Lisp, here is how you would get it anyway:

(defmacro my-lambda ((&rest args) &body body)
(let ((def (gensym)))
`(flet ((,def (,@args) ,@body))
(function ,def))))

This macro effectively hides how you get at the first-class anonymous
function, so that your client code doesn't need to see this anymore. In
Java (and similar workarounds for the Python) the internals of how a
concept is realized leak because there is no (or not enough) way to hide
them. This leakage causes problems, essentially because you are forced
to think in terms of your implementation language, not in the concepts
of the problems you are trying to solve. This requires you to
continually translate concepts between two worlds, and this is a source
of bugs.

Don't subject yourself to the dictatorship of someone else, no matter
how benelovent they appear to be, because they don't know your
requirenments in the first place. It doesn't really matter whether a
specific feature is in the language or not. It's surely nice when a
language has lots of useful features to begin with because this reduces
your need to reinvent wheels. However, it's much more important whether
you can shape the language to your needs.


Pascal

--
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/

Eric Lavigne

unread,
Jul 6, 2005, 1:41:30 PM7/6/05
to
>So, if you're a pythonista who loves map and lambda, and disagrees with
>Guido, what's your background? Functional or not?

>tom

Interesting poll. Ask a bunch of Python programmers whether they have a
background in functional programming...

Don't you think it skews your results just a little that you are
looking in comp.lang.lisp?

>I disagree strongly with Guido's proposals, and i am not an ex-Lisp,
>-Scheme or -any-other-functional-language programmer; my only other
>real language is Java. I wonder if i'm an outlier.

Haven't tried Lisp yet? There is a solution to that... Forget about
wishing that you liked your chosen language. Instead, choose the
language that you like.

Joe Marshall

unread,
Jul 6, 2005, 1:52:09 PM7/6/05
to
"Steve" <steve...@gmail.com> writes:

> Comrades,

I know I shouldn't feed the trolls, but...

> During our current discussion of the fate of functional constructs in
> python, someone brought up Guido's bull on the matter:
>
> http://www.artima.com/weblogs/viewpost.jsp?thread=98196
>
> He says he's going to dispose of map, filter, reduce and lambda. He's
> going to give us product, any and all, though, which is nice of him.

He is, after all, benevolent.

> What really struck me, though, is the last line of the abstract:
>
> "I expect tons of disagreement in the feedback, all from
> ex-Lisp-or-Scheme folks. :-)"
>
> I disagree strongly with Guido's proposals, and i am not an ex-Lisp,
> -Scheme or -any-other-functional-language programmer; my only other
> real
> language is Java. I wonder if i'm an outlier.

Certainly within the python community.

> So, if you're a pythonista who loves map and lambda, and disagrees with
> Guido, what's your background? Functional or not?

``I think having the two choices side-by-side just requires
programmers to think about making a choice ...; not having the
choice streamlines the thought process.'' -- Guido van Rossum

and as Oscar Wilde has pointed out:

``Thinking is the most unhealthy thing in the world, and people die
of it just as they die of any other disease. Fortunately, in
England at any rate, thought is not catching.''

It is fortunate for pythonistas as well.

Dan Schmidt

unread,
Jul 6, 2005, 5:20:55 PM7/6/05
to

I use Python and have a background in functional programming, and I actually don't care that much about whether these features go away.

The facts are that right now, map and filter can generally be replaced more perspicuously by list comprehensions; anonymous functions are super ugly and can only consist of a single expression; and because of the annoyingness of anonymous functions, nobody uses reduce much except to take sums or products. If Python were a different language I might care more.

When I am using ocaml or something, I map and filter and fold like the dickens, but in Python it really doesn't come up as much.

rsher...@gmail.com

unread,
Jul 6, 2005, 5:47:16 PM7/6/05
to

Steve wrote:
> Comrades,

>
> He says he's going to dispose of map, filter, reduce and lambda. He's
> going to give us product, any and all, though, which is nice of him.
>
> What really struck me, though, is the last line of the abstract:
>
> "I expect tons of disagreement in the feedback, all from
> ex-Lisp-or-Scheme
> folks. :-)"

Python's map doesn't do as much as Lisp's analogs of it, and neither
map nor filter do anything that list comprehensions don't. There's no
point to having them in Python, unless you want your Python code to
look like Lisp, in which case you should just use Lisp. Python's
lambda is also wimpy and castrated compared to Lisp's. It would have
been better to fix it, but putting it out of its misery is reasonable.

I don't know about reduce. I use it (and especially fold) all the time
in functional languages, and Guido is totally wrong to suggest that
it's only useful for summing lists. Maybe it's just not the Python
way. I prefer languages where you're not at the mercy of a BDFL for
simple language features like this.

> I disagree strongly with Guido's proposals, and i am not an ex-Lisp,
> -Scheme or -any-other-functional-language programmer; my only other
> real
> language is Java. I wonder if i'm an outlier.

Probably so, or he wouldn't be doing it.

> So, if you're a pythonista who loves map and lambda, and disagrees with
> Guido, what's your background? Functional or not?

I wouldn't go so far as to call myself a pythonista, but it was my
first language and I've been using it lately for a project that I
intend to hand over to people who would probably not appreciate having
to maintain code written in a weird AI language. I usually program in
a functional style, but even so, I don't see any reason to miss these
features.

John

unread,
Jul 6, 2005, 10:36:01 PM7/6/05
to
On 2005-07-06, Steve <steve...@gmail.com> wrote:
> So, if you're a pythonista who loves map and lambda, and disagrees with
> Guido, what's your background? Functional or not?

I love LISP but I must admit that I write python programs far more
often. After reading Guido's paper I went looking through my python
programs looking for times I used filter/reduce/map/lambda. I found
several cases and started changing them to list comprehensions.

Ignore reduce for a moment, I found that at least in my programs every
time I was using filter/map/lambda the code was easier to read when I used
a list comprehension instead. Its not entirely suprising I wasn't using
list comprehensions a lot though since I learned python before they were
added to the language and I already knew LISP.

As for reduce, every single reduce I had in any of my python programs was
just adding numbers. I never went looking for the sum() function as I
already knew reduce and when you only have a hammer everything looks like
a nail.

So I'm going to have to agree with Guido. I think filter/map/lambda are
pretty pointless in python and his statement that + and * are the common
use cases for reduce have been proven correct (at least in my code).

Just my $.02

Reply all
Reply to author
Forward
0 new messages