[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Nick Coghlan ncoghlan at gmail.com
Wed Sep 28 12:27:43 CEST 2011

On Wed, Sep 28, 2011 at 6:14 AM, Carl Matthew Johnson
<cmjohnson.mailinglist at gmail.com> wrote:
> On Sep 27, 2011, at 11:59 PM, Nick Coghlan wrote:
>>    def accumulator():
>>        def incr(x) [tally=0]:
>>            tally += x
>>            return tally
>>        return incr
> Brackets feel too much like line noise… A keyword?

Hah, def statements are already line noise if you use the full syntax :)

def theheck(do:all, these=1, *different, symbols, **mean) -> seriously:
    """And this is special, too!"""

I think the combination of position with the different bracket style
is enough to separate them out from the parameter list and their
position in the function header eliminates much of the confusion
associated with the various syntax proposals for state variables
inside the function body. I actually think it also serves as a mild
deterrent to abuse - code that overuses function state variables is
likely reaching the point where it needs to be rewritten as a class,
and this would be reflected in the unwieldiness of the function


[1] http://docs.python.org/py3k/reference/compound_stmts.html#grammar-token-funcdef

Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list