[Python-ideas] a new lambda syntax

Jim Jewett jimjjewett at gmail.com
Thu Oct 22 02:41:04 CEST 2009

On Tue, Oct 20, 2009 at 7:34 AM, Masklinn <masklinn at masklinn.net> wrote:
> But unless the language is dynamically scoped (which is getting pretty rare
> these days, and which Python definitely isn't)

err ... current python.  I believe that changed around python 2.2.

I've wanted a way to reverse that more often than I've wanted a way to
avoid naming a function.  (I originally wrote "far more", but ... the
urge doesn't actually come up most years, so maybe it was a solution
finding a problem.)

> The biggest (by far) advantages I see to good anonymous functions (note:
> Ruby's aren't, as far as I'm concerned, because due to their nature they
> don't easily scale from 1/call to 2+/call) are in flexibility, freedom of
> experimentation and possibility to keep the core language itself small: had
> Python had "full-blown" anonymous functions, it wouldn't have been necessary
> to add the `with` statement to the language.

I'm not sure how the lack of a name buys you any of that.  Callables
as first-class objects that can be passed around, yes -- but naming
them is fine.  And to be honest, that flexibility and freedom seem
like they would be amplified by dynamic scope, so that you could
"tune" library functions by passing in arbitrary callables that could
affect the "local" variables.  The advantages of lexical scoping seem
to be mostly about closures, rather than about extending an existing
external function.

Could you explain how (even named) multiline functions (as opposed to
dynamic scope) would have served in place of "with:"?


More information about the Python-ideas mailing list