Of what use is 'lambda'???

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Thu Sep 21 11:31:56 EDT 2000


Thu, 21 Sep 2000 13:40:11 GMT, Guido van Rossum <guido at beopen.com> pisze:

> There's a difference between the need for lambda in Python and in most
> other languages -- certainly elisp.
> 
> In elisp (AFAIK), when you define a function, the name you give it is
> globally registered, so you need to make sure it doesn't conflict with
> other functions.  Anonymous functions defined with lambda avoid this.

Well, I would not say that it's "most other languages". It is not a
problem in SML, OCaml, Haskell, Clean, and I think Erlang.

OTOH I think that one reason of using lambda in some other languages
more often than in Python is full lexical scoping - so lambda is less
ugly compared to alternative styles.

Also usually there is no restriction that the body of lambda must be a
"single expression" (e.g. by making no distinction between expressions
and statements).

Another reason of using lambda might be, paradoxically, the ability
of creating functions without lambda - by partial application of
curried functions or other constructs, e.g. "map (2*)" is a function
from list of numbers to a list of numbers. Convenient ways to define
function objects lead to functions that take functions as arguments,
which lead to lambda in more complex usages.

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



More information about the Python-list mailing list