[Python-ideas] An Alternate Suite Delineation Syntax For Python? (was Re: [Python-Dev] [PATCH] Adding braces to __future__)

Ron Adam ron3200 at gmail.com
Sat Dec 10 08:33:01 CET 2011

On Sat, 2011-12-10 at 15:06 +1000, Nick Coghlan wrote:
>   One-liner accumulator function:
>     def acc(n) {: s=n; return {: def (i) {: nonlocal s; s += i; return
> s}}} 

>>> def acc(n):s=n; return lambda i, s=s: s+i
>>> a = acc(2)
>>> a(1)
>>> a(3)
>>> a(7)


In your example returning an unnamed function is a new feature in
addition to the braces.  It would probably need to be more like this...

def acc(n){:s=n; def add(i){:nonlocal s; s+=i; return s};return add}

There are a couple of issues to work out.  Statements (def, class, for,
while, and with) don't work after simi-colons. There may be others.

Outside those issues, all you really need is an exit suit token.  The
colon can still be the open suit.  Two semi-colons could do it.

def acc(n):s=n; def add(i):nonlocal s; s+=i; return s;; return add

The real issues are in getting the statements to work.


More information about the Python-ideas mailing list