[Tutor] Are you allowed to shoot camels? [kinda OT]

Alan Gauld alan.gauld at freenet.co.uk
Fri Feb 4 00:17:11 CET 2005


> >> Pythons lambda feature is a bare minimum (and Guido wants to
remove
> >> it!).

> However, Python doesn't need lambdas to be able to write in a
> functional style.

I disagree Jeff. It does need lambdas to do FP properly, and
better lambdas than we have currently. What it doesn't need
is the lambda keyword and syntax - although pesonally I like
lambda since it is descriptive!

> Functions are first-class objects and can be passed
> around quite easily,

Yes, but lambdas are more than first class functions, they
are anonymous functions! In fact really just callable code
blocks, not necessarily functions in the strictest sense
(except that every callable in FP is a function...! ;-)
Having to define every function before using it would
be a big hassle and make code less readable IMHO.

> borrowed (though probably with notable modification) from Haskell.

Conceptually not much modification, but the two syntaxes
are poles apart!

> only a few differences between lambdas and named functions in
Python:
>
>    - Anonymous vs named

the key feature

>    - Single expression vs suite of statements

A python restriction.

>    - Inline vs. pre-created

A key usage point

> Note that the second of these is a consequence of the third

Again a Python restriction. And hard to see how you avoid given
Pythons structure.

> I'd also argue that the inline nature is the *true* differentiating
> feature of lambdas -- the fact that they're anonymous is relatively
> minor.

I agree, if I had an inline mechanism that forced me to
provide a name I could just use 'f' over and over and
not feel too cheated, but its nicer not to have an artificial
name when theres no need.

> So, while there are some advantages to having single-use callables
be
> defined inline

The other advantage is the huge conceptial advantage that
real lambdas confer. The breakthrough idea of

def f(x): return x+x

being the same as

f = lambda x: x+x

is only possible to demonstrate if you have lambda to start with.
And yet that concept of a function name being just another variable
and the callable code being an object in its own right becomes
much more obvious in my opinion. lambda is a learning tool which
shows what is really happening whereas def is just syntactic sugar.

> (And personally, I suspect that if lambdas *are* removed, they will
be
> replaced with a different construct that will fill the same needs in
a
> more Pythonic way...)

I believe (and hope) this too. Certainly the stink it has created on
c.l.p should hopefully convince Guido that there is a groundswell
of demand for the facility if not the name...

Alan G.



More information about the Tutor mailing list