Let's Talk About Lambda Functions!

Tim Peters tim.one at comcast.net
Mon Jul 29 05:26:17 EDT 2002


[Fredrik Lundh]
> Guido can channel himself (or Tim will do it), but from what
> I can tell, he's always said that the "mistake" was adding
> something to the language that almost, but not completely,
> works like lambdas do in other languages.

I don't think so -- Guido isn't a fan of functional programming styles, and
plain doesn't like lambda.  Except, of course, when he uses it, which is
always for trivial little function arguments, in accord with his
oft-repeated claim that the functional gimmicks were never intended to be
more than "minor conveniences" (which he later amended to "minor
annoyances", after people started clamoring for more of the same).  It's not
that they don't work exactly the same way in Python as some people expect
them to, it's more that programming styles based on composition of
higher-order functions simply aren't in his vision of what programming in
Python should be.

> (lambda, map, filter, etc was contributed code)

Change "etc" to "and reduce" and you've got the whole set.  Those four were
contributed by the same person, in one gulp.  I don't think Guido has tried
it, but he'd like Haskell much more than he'd like Scheme; e.g., listcomps
"felt right" to him, while non-trivial maps and filters don't, and never
will.

> the really big usage problem (whether you knew lambdas
> from other languages or not) used to be that they were a
> real pain to use under the LGB scoping rule.  with the intro-
> duction of nested scopes, that problem no longer exists.

Guido's not much of a fan of nested scopes, either, although I believe I've
channeled evidence of minor flip-flopping on that.  Indeed, by and large
people seemed quite happy with the LGB rules *until* lambda got introduced.
Then "scope whining" started for real.  I expect he'll stay happy enough
with lexical scoping until people start writing inscrutably nested
monstrosities with it.  Objects are Python's intended way to carry state,
and Guido isn't a Paradigm-Neutral language designer (you know where to go
if you want one of those).

> to fix the other "mistake", some needs to come up with a
> really great syntax (and get michael hudson to implement
> it for them ;-).  ideas are welcome.

Well, I can channel that one:  not bloody likely.  If Guido's time machine
wasn't in the shop for million-year warranty service, I expect Python
wouldn't have any spelling of anonymous functions today.  Note that toward
the tail end of Guido's OSCON 2002 "State of the Python Union" keynote
address:

    http://www.python.org/doc/essays/ppt/ [bottom link on the page]

two language features are mentioned as being "failed experiments" that only
compatibility prevents throwing away:

    `back ticks`
    lambda

With subtle clues like that, channeling is easier than it looks <wink>.





More information about the Python-list mailing list