I'd like to use this syntax only in situations of PEP 312, that is, where a colon is prohibited by current grammar. In those situations, writing _: is also prohibited by current grammar so it will be parsed unambiguously. The examples you quoted will not change under my idea, but ``x = (_:_*2)`` would be possible as an alternative. Note that I would be against being able to use ``x = _:_*2``. I think it's better to require either lambda keyword or parentheses for the RHS of the assignment as colon has a well-defined meaning as starting an indented block unless it's inside some brackets. On Fri, Aug 7, 2009 at 4:58 PM, Gerald Britton<gerald.britton@gmail.com> wrote:
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@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@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- Gerald Britton