lambda and for that matter goto not forgetting sugar
Nick Coghlan
ncoghlan at iinet.net.au
Thu Feb 10 09:50:34 EST 2005
Philip Smith wrote:
> I've read with interest the continuing debate about 'lambda' and its place
> in Python.
>
> Just to say that personally I think its an elegant and useful construct for
> many types of programming task (particularly number theory/artificial
> intelligence/genetic algorithms)
>
> I can't think why anyone would be proposing to do away with it. Sometimes
> an anonymous function is just what you need and surely it just reflects the
> python philosophy of everything being an object (in this case a code
> object).
The *concept* is fine, but the current syntax is seriously ugly, and the keyword
used creates false expectations for those familiar with what lambda calculus
actually *is*.
If the lambda syntax were a new proposal to be added to the language now, it
would never be accepted.
Unfortunately, its existence tends to stymie efforts to come up with a
*Pythonic* way of spelling the same idea. The people who want to get rid of
lambda completely think coming up with a new spelling is a waste of time - "Just
define the damn function already!" is their rallying cry. The people who want
real lambda calculus complain that they still can't put statements inside
expressions - they shout "Give me real anonymous functions, not this neutered
junk that restricts me to a single expression!". And, of course, there's always
someone to complain that supporting a new spelling would violate TOOWTDI - "But,
but, we already have def and lambda, why are you trying to come up with yet
another way to create a function?".
Anyway, check out AlternateLambdaSyntax on the python.org Wiki if you haven't
already. For my own part, I'd like a new spelling. Something that is more
stylistically in line with a genexp would be significantly preferable to the
status quo (e.g "(x*x from (x))" aligns better with "(x*x for x in seq)" than
"lambda x: x*x" does).
> Following on naturally from that last point I would also like to 'deprecate'
> the use of the expression 'syntactic sugar' on these pages. All high level
> languages (Python included) are nothing but syntactic sugar designed to
> conceal the ugliness of what actually gets sent to the CPU to make it all
> happen.
Yup, you're right. But 'syntactic sugar' often isn't used in a negative way -
it's more descriptive than anything. It's any language change that's designed to
make common idioms easier to use.
Cheers,
Nick.
No comment on the goto thing ;)
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list