Looks like Lisp(Lots of Irritating Stupid Parenthesis). Hehehe.


On Tue, Oct 22, 2013 at 5:10 AM, Antony Lee <antony.lee@berkeley.edu> wrote:
As the issue has been (indirectly) raised again in the recent context manager thread, I would like to propose yet another syntax for multiline lambdas...  I know there has been many but I (foolishly?) hope this one is simpler.  I do not wish to focus on the usual arguments for and against the usefulness of such a construct (from the archives of the list, I feel that the lack of an attractive syntax is the bigger barrier).

Specifically, I suggest that the "def" (and possibly the "class") keyword(s) may be used in an expression context, if immediately surrounded by parentheses.  The indentation of the body of the function is given by the indentation of the first line after the def.

target = (def f(arg):
    <...>)

add_callback(
    def callback(arg):
        <...>)

callbacks = {
    "foo":
        (def foo():
            <...>), # note how the parentheses disambiguate where the last comma belongs
    "bar":
        (def bar():
            <...>)
}

As an extra suggestion, one may want to allow not specifying a function name in these contexts:

callbacks = {
    "foo":
        (def ():
            <...>)
}

(in which case the function would be named "<lambda>", of course) but I do not think that this is a critical feature (and it could always be added later).

Feel free to critique,

Antony

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas




--
Ryan