[Python-Dev] Recommend accepting PEP 312 -- Simple Implicit Lambda

Nick Coghlan ncoghlan at gmail.com
Tue Jun 21 17:13:01 CEST 2005


Guido van Rossum wrote:
> [Nick Coghlan]
> 
>>And here we see why I'm such a fan of the term 'deferred expression'
>>instead of 'anonymous function'.
>>
>>Python's lambda expressions *are* the former, but they are
>>emphatically *not* the latter.
> 
> Let me emphatically disagree. Your POV is entirely syntactical, which
> IMO is a shallow perspective. Semantically, lambdas ARE anonymous
> functions, and that's what counts.

Interesting. Knowing this, I think I better understand your desire to 
get rid of lambda expressions for Py3K.

> Since "deferred expression" is not defined in Python, you can't
> reasonably argue about whether that's what lambdas are, but
> intuitively for me the term refers to something more lightweight than
> lambdas.

As you say, it is a matter of looking at lambdas based on what the 
current syntax restricts them to (i.e. single expressions), rather 
than what the underlying machinery is capable of (i.e. full-fledged 
functions).

> Now, whether the use cases for lambdas are better served by anonymous
> functions or by something else that might be called deferred
> expression, I don't know yet. 

Like you (judging by your stated goals for Py3K), I don't have any use 
cases for full anonymous functions - named functions serve that role 
quite happily for me.

Where I find lambda expressions useful is the role that Python's 
current syntax restricts them too - functions which consist of a 
single (usually simple) expression. For those, pulling the expression 
out and naming it would just end up hiding the meaningful sections of 
code behind a few pieces of boilerplate

 > But as long as we are describing the
 > present state we should call a spade a spade, etc.

I guess I take a syntactic view of the status quo, because, while 
lambdas may be implemented as anonymous functions, the current syntax 
doesn't let me *write* an arbitrary function as a lambda.

Regardless, I believe the balance will eventually tip in some 
direction - either lambdas disappear entirely, become able support 
full anonymous functions, or else the idea of a 'deferred expression' 
becomes a defining characteristic, rather than a syntactic quirk.

I figure it's all Py3K type stuff though, without any great urgency 
associated with it.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list