Alex Martelli wrote: > Xavier Morel <[EMAIL PROTECTED]> wrote: > ... >> Wouldn't it be possible to change the `def` statement to return a >> reference to the function, and allow omitting the function name thereby >> bypassing the default binding (current behavior)? > > It's _possible_ (doesn't introduce syntax ambiguities) though it does > introduce incompatible interactive-interpreter behavior, as you say: > >> >>> # Extended behavior >> >>> # returns a reference to the function >> >>> def foo(*args, **kwargs): >> pass >> <function at 0x00FA37B0> > > This could be avoided if 'def <name><etc>' remained a statement like > today, and a separate expression 'def<etc>' returned a function object > as a result; this would have the aded plus of avoiding the totally new > (to Python) idea of "statement returning a value" (_expressions_ return > a value). > True that, I didn't even consider the possibility to create an independent expression.
And it completely remove the possibility to generate the first "con". >> * May allow for blocks-like constructs (I'm not sure of the current >> state of the closures over Python functions though, these may have to be >> extended to "full" closures if they aren't) and be considered by some as > > Python's closures are 'full', but don't allow inner functions to rebind > names in the namespace of outer functions. > > I'm not sure a PEP like this has ever been proposed, but the idea of > anonymous def is not new (bar some details of your proposal): if a PEP > doesn't exist, you could write one, at least to firm up all details. > > > Alex Or maybe start by creating a thread on the subject of an anonymous def expression on this list first? -- http://mail.python.org/mailman/listinfo/python-list