[Python-ideas] pep 312 - implicit lambdas idea

Gerald Britton gerald.britton at gmail.com
Fri Aug 7 14:58:28 CEST 2009


The underscore is already a viable identifier:
>>> _ = lambda x:x*2
>>> _(3)
6

and

>>> x = lambda _:_*2
>>> x(3)
6
>>>


So I don't think you can use it the way you're proposing without breaking
existing programs


On Fri, Aug 7, 2009 at 8:46 AM, ilya <ilya.nikokoshev at gmail.com> wrote:

> I was thinking about a good syntax for implicit lambdas for a while
> and today I had this idea: make ``_:`` a shortcut for ``lambda
> _=None:``
>
> 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?
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
Gerald Britton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090807/20f36c16/attachment.html>


More information about the Python-ideas mailing list