[Python-ideas] Syntax for passing lambdas to functions

Joshua Landau joshua at landau.ws
Thu Feb 27 19:48:25 CET 2014


On 27 February 2014 18:27, Antony Lee <antony.lee at berkeley.edu> wrote:
> Now that someone mentioned dispatch tables, another possibility would be to
> support assignment to tables and monkey-patching directly, with a syntax
> like
>
> def obj.method(*args): ... # __name__ = "method" (the attribute name)
> def table[key](*args): ... # __name__ = ??? (perhaps "table[key]"?)
> (and also any other "lvalue".)

I would very much support this. It's actually odd that you *can't* do
it, considering you *can* do

    class A: ...
    a = A()
    l = [0]

    for a.x in [1, 2, 3]: ...
    for l[0] in [1, 2, 3]: ...

However, there are disadvantages:

    potentially ambiguous grammar
    (very) small chance of misuse
    could hurt introspection

Further, I don't imagine I'd use it frequently. Just enough, though.


More information about the Python-ideas mailing list