[Python-Dev] Extended Function syntax

Samuele Pedroni pedronis@bluewin.ch
Sun, 2 Feb 2003 21:17:30 +0100


From: "Guido van Rossum" <guido@python.org>
> [Samuele]
> > yes, real-world examples would be good.
>
> synchronized() is definitely a real-world example -- writing
> try/finally for locks is a pain for all threaded code.
>
> Another, related example would be something that blocks all signals
> (or at least SIGINT) during a certain code block.
>
> I imagine that there are quite a few examples that basically wrap a
> code block in something that does some preparation and some cleanup.
>
> These require that the cleanup action is done even if an exception
> occurred in the block, and this can't be done with the "for loop" hack
> proposed by Armin (unless you rely on __del__, which would be a no-no
> for Jython).
>
> 'do' or 'with' should be up to this task.

with 'do' you mean your 'do' whose thunk can rebind locals?

> I think that for synchronized-like cases, even if it is known at
> compile time that it is to be part of the surrounding scope, the code
> generated will still need to use nested-scope-cells, since it will be
> invoked on a different stack frame: the "thunk processor" pushes its
> own frame on the stack, and I think you can't have something that
> executes in a frame that's not the topmost frame.  (Or can you?  I
> don't know exactly what generators can get away with.)

How can you avoid that someone stores away the thunk, you would need a special
keyword to invoke it (Ruby uses "yield" which here is already taken), then we
still have return/break/continue semantics to get right, whether we want
'value' or not'...

If I understand correctly you are still proposing to have:

a 'do' and thunks that can mess with locals with their headaches <.5 wink>, and
new concepts added to the language.

On my part, I'm still wondering whether Michael Hudson's 'with' and my 'fdo'
(maybe still to name just 'do'), that uses an anonymous function as-we-know-it,
not a thunk will give most of the functionality without enlarging the language
(they are basically sugar, useful sugar).