[Python-3000] A plea for anonymous functions

Jim Jewett jimjjewett at gmail.com
Thu Nov 16 17:37:48 CET 2006


On 11/16/06, Talin <talin at acm.org> wrote:
>  From my point of view, both 'with' and generator expressions are
> limited, special-case solutions to a general problem - the desire to be
> able to use and manipulate unnamed blocks of code as first-class
> objects.

Other than your callback of a curried function, I don't think the
suites really need to be anonymous; first class is enough.

And even that may be overkill; I didn't see any examples that didn't
boil down to "If I wrote this normally, it would execute in the wrong
namespace."   (I may be undervaluing the "but I haven't defined it
*yet*" portion of your examples.)

> Conversely, the same arguments that make 'with' important
> enough to change Python syntax - instead of just saying 'use a named
> function'

The wrapping portions often are named.  The point of "with" is to tie
them together as a single named function instead of two paired
functions.

The center suite (inside the "with") can't always be replaced by a
function, and that is because it needs to be evaluated in the same
scope as the suites before and after the with block.

> 2) Many of those 'workarounds' are going to come back in the form of
> PEPs to add new language features. I predict that we'll see a
> never-ending parade of enhancement proposals - lazy evaluation
> expressions, asynchronous callback expressions, and so on - all of which
> are in a sense compensating for the lack of the ability to treat code
> like data.

If not for the special-case treatment of locals and globals, I can't
quite think of an example that couldn't be rewritten as a suite, and
called with exec.

Just for nostalgia...

    suite core:
        stmt1
        stmt2

-jJ


More information about the Python-3000 mailing list