Of what use is 'lambda'???

Gareth McCaughan Gareth.McCaughan at pobox.com
Thu Sep 21 15:42:29 EDT 2000


Guido van Rossum wrote:
> 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.

This isn't true in Common Lisp and Scheme, which are the
most important modern Lisp dialects[1].

In Common Lisp, there's a mechanism for binding locally-defined
functions just as there is for binding locally-defined variables.
(It doesn't look exactly the same as the mechanism for defining
functions globally at top level; but then, the mechanism for
binding local variables also doesn't look exactly the same as
the one for doing it globally at top level.)

In Scheme, you can use the exact same syntax internally as
you use at top level. (Up to R4RS, this was an optional
part of the language, though almost every implementation
supported it. As of R5RS it's mandatory.)

Elisp is terribly unrepresentative of modern Lisps.


Of course, there's also a difference in *utility* between
Python and (modern) Lisps, in that their lambdas make
lexical closures and Python's don't. The default-parameter
dance doesn't exactly make for concise and elegant code.
(I know, I know, this holy war has been done to death
long ago...)


[1] Depending on exactly what "modern" means, of course;
    elisp and Autolisp are in widespread use today, but
    I wouldn't call them "modern".

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
sig under construc



More information about the Python-list mailing list