[Python-Dev] Let's just *keep* lambda

Brett Cannon brett at python.org
Tue Feb 7 22:52:51 CET 2006


On 2/7/06, Paul Moore <p.f.moore at gmail.com> wrote:
> On 2/7/06, Brett Cannon <brett at python.org> wrote:
> > On 2/5/06, Guido van Rossum <guido at python.org> wrote:
> > > After so many attempts to come up with an alternative for lambda,
> > > perhaps we should admit defeat. I've not had the time to follow the
> > > most recent rounds, but I propose that we keep lambda, so as to stop
> > > wasting everybody's talent and time on an impossible quest.
> >
> > I have been thinking about this, and I have to say I am a little
> > disappointed (-0 disappointed, not -1 disappointed).  I honestly
> > bought the argument for removing lambda.  And I think that a deferred
> > object would help with one of lambda's biggest uses and made its loss
> > totally reasonable.
>
> I'm not 100% sure what you mean here, but as far as my understanding
> goes, current lambda *is* a "deferred object" (or at least a "deferred
> expression", which may not be quite what you mean...)
>

Yes, lambda is deferred.  What I mean is using lambda for things like
``lambda x: x.attr`` and such; specifically for deferred execution,
and not for stuff like ``lambda x: func(1, 2, x, 3, 4)`` stuff.

> > But I know that everyone and their email client is against me on this
> > one, so I am not going to really try to tear into this.  But I do
> > think that lambda needs a renaming.
>
> I agree with this. The *name* "lambda" is a wart, even if the deferred
> expression feature isn't. My preference is to simply replace the
> keyword lambda with a keyword "expr" (or if that's not acceptable
> because there's too much prior use of expr as a variable name, then
> maybe "expression" - but that's starting to get a bit long).
>
> > Speaking as someone who still
> > forgets that Python's lambda is not the same as those found in
> > functional languages,
>
> Well, only in the sense that Python's *expressions* are not the same
> as those found in functional languages (ie, Python has statements
> which are not expressions). But I see your point - and I strongly
> object to going the other way and extending lambda/expr to allow
> statements or suites.
>
> > I would much rather have it named 'expr' or
> > 'expression' or something that is more inline with its abilities then
> > with a name taken for CS historical reasons.  This ain't for father's
> > lambda and thus shouldn't be named so.
>
> Agreed. But if "expr" isn't acceptable, I don't like the other common
> suggestion of reusing "def". It's not a definition, nor is it "like an
> anonymous function" (the lack of support for statements/suites being
> the key difference).
>

Yeah, reusing def is taking back into the functional world too much. 
It makes our current use of def seem more like syntactic sugar for
assigning a lambda to a name for function definition and that is not
what is happening here.

> > Then again, Guido did say he "should", not that he "did" admit defeat.  =)
>
> OTOH, he was trying to stop endless the discussion... :-)
>

=)  Well, it should when Python 3 comes out, so there is some extra
incentive for that to happen sooner than later.

-Brett


More information about the Python-Dev mailing list