[Python-Dev] Re: Extended Function syntax

Samuele Pedroni pedronis@bluewin.ch
Thu, 30 Jan 2003 14:14:05 +0100


From: "Guido van Rossum" <guido@python.org>
> Then there are two possibilities for the body:
>
> (1) it could be evaluated before the xdef statement is "executed"
>     (just as a class body);
>
> (2 or it could be compiled into a "thunk" which is somehow passed to
>     whatever is called to implement the xdef (like a function body).
>
> Variant (2) gives much more freedom; it would allow us to create
> functions that can be called later, or it could be executed on the
> spot to yield its dictionary.
>
> > So this would work like:
> >
> >     name = mod2(mod1(name, args, kw_args, dict))
>
> Variant (2) would have the thunk object instead of dict.
>
> I think a thunk should be a callable; upon execution it would return
> its dict of locals.
>
> Maybe if a thunk contains a 'return' statement it could return the
> return value instead.
>
> Maybe someone can find a use for a thunk containing 'yield', 'break'
> or 'continue'.
>
> Maybe all control flow in the thunk should raise an exception that the
> xdef can catch to decide what happens.  Hm, if it did 'yield'
> you'd like to be able to call next() on it.  So maybe there should be
> different types of thinks that one can distinguish.

Can you modify the locals of the surrounding (function) scope in the thunk, or
its an anonymous closure with the current nested scopes rules (no rebinding)?

I honestly find that trying to use a single extension to solve very different
problems is a bad idea, e.g. currently class is semantically very different
from control flow statements,  the idea that a single extension can offer
extensions for both up to general syntax extensibility seems far stretched.

Personally I would find the addition of:

1) [] extendend function syntax to def (and possibly class and 2)
2) a statement that captures and extends what class does now ("my" proposal)
3) a 'with' statement for semantics like those of CL with- macros (Michael
Hudson has some ideas on this)

more pythonic.

General syntax extensibility is another level of identity crisis for the
language <wink>.

regards