[Python-Dev] Extended Function syntax
Samuele Pedroni
pedronis@bluewin.ch
Sun, 2 Feb 2003 20:21:05 +0100
From: "Samuele Pedroni" <pedronis@bluewin.ch>
> From: "Guido van Rossum" <guido@python.org>
> > I think so far I've been thinking mostly about fitting my proposal on
> > all edges (that's where my discussion of the thunk's scope comes
> > from). Maybe I should try to focus more on collecting real-world
> > examples that are asking for syntactic support, and then try to look
> > for the simplest way to support most of them.
>
> yes, real-world examples would be good.
In particular real-world examples, not covered by 'for' and generators or
'with'*, that need rebinding the surrounding function locals and/or non-local
return.
[Just for fun, on the hackery/contrived side of things, we would finally get a
version of Paul Graham's accumulator generator
http://www.paulgraham.com/accgen.html
with mostly lisp-y length:
def accmaker(n):
do acc = (lambda x:x): (i):
n += i
value n # ! not 'return', that would be a non-local return
return acc
]
*
with <expr>:
<suite>
would be possibly sugar for:
_x = <expr>
_x.__enter__()
try:
<suite>
finally:
_x.__exit__()
OR:
_x = <expr>
_x.__enter__()
try:
try:
<suite>
except getattr(_x,'__excepts__',()),_e:
_x.__except__(_e)
finally:
_x.__exit__()