[Python-ideas] pep 312 - implicit lambdas idea

ilya ilya.nikokoshev at gmail.com
Fri Aug 7 14:46:40 CEST 2009

I was thinking about a good syntax for implicit lambdas for a while
and today I had this idea: make ``_:`` a shortcut for ``lambda

For example:

    map( _: _ + 5, some_list)
    register_callback( _: True)
    def apply_transform(..., transform = _:_, ... ):

but still

    addition = lamba x, y: x + y

The rationale is that you only want to get rid of lambda keyword to
create a *very* simple function, the one that will be called either
without parameters or with only one parameter. For everything more
complicated, you really should go and write the explicit function
signature using lambda.

Even though ``:`` could theoretically denote implicit lambda, it's too
easy to miss it. The combination ``_:`` is much easier to notice. It
also makes explicit that there is at most one parameter and it's name
is ``_``. Since it's very short, it can easily be used in a long
function call or as a default parameter, as above

Your thoughts?

More information about the Python-ideas mailing list