Lambdas (was Re: [RFC] Draft Proposal for New Python Syntax)

Tim Peters (tim@ksr.com)
Fri, 27 May 94 13:57:51 -0400

> > [guido]
> > ... [lambdas] are entirely syntactic sugar for local function
> > definitions. Everything you can do with lambda you could always do
> > with local functions, at the cost of one local temporary identifier --

> Perhaps I do not understand if your point is about lambdas in Python
> or lambdas in general.

It was the former, i.e. Guido was talking about Python's lambda
specifically.

> ...
> The lambda in a functional language is more like syntactic sugar for a
> class definition that has only one method and then creating an instance
> of it. The class definition needs to hold all the unbound variables
> occuring in the lambda body and the creation of the instance sets those
> values.

Absolutely, and the way to do that kind of thing in Python is in fact to
define a class, explicitly passing to its constructor the values that a
functional language with lexically nested scopes & closures would capture
"by magic"; the recent keyword-argument extension to Python can be abused
to achieve the effect via Python's lambda, but that's really not a
natural approach for Python. I often like the class approach better, cuz
the set of interesting values is made explicit, and the class defn is
sometimes useful or convenient in other contexts too.

> Lambdas are useful for much more than making function arguments for
> map and reduce operators.

Python's lambda or lambdas in general <wink>?

imperatively y'rs - tim

Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp