[Python-ideas] Before and after the colon in funciton defs.

Jan Kaliszewski zuo at chopin.edu.pl
Thu Sep 22 03:01:40 CEST 2011


I'm adding both new propositions:

1. the `def foo(...) [len=len]:` syntax,
2. the `len = (static len)` expression syntax

-- to the PEP-draft I'm preparing -- which Nick suggested in June
[http://mail.python.org/pipermail/python-ideas/2011-June/010569.html]
(I'm sorry that that preparing lasts so much time, but my everyday-
-activity-CPU has been overloaded a bit for a few months...).


Ad 1: I think it's better than the `after-**` proposition from June,
though still has some its drawbacks (Sven just mentioned some of them).


Ad 2: I must admit that this one becomes my favorite syntax for
early binding (though I don't like the abbreviated form '(i=i)').

IMHO it's not only clear (no all that questions about assignment
semantics) but also elegant, explicit and consistent with some existing
syntax constructs (especially with `yield EXPR`).

Note that (as you can use any expression) it makes possible to use e.g.
tuples of several names:

    spam, print, open = static (len, print, open)

Big +1 from me.


3. Another variant could be with a colon (a bit similar to the lambda
syntax):

    len = static: len
    spam, print, open = static: (spam, print, open)

or even (reusing the existing keyword):

    len = def: len
    spam, print, open = def: (spam, print, open)

(here "def" means: "at definition time")

But I'd rather prefer the #2.


Regards.
*j




More information about the Python-ideas mailing list