[Python-ideas] explicitation lines in python ?

Nick Coghlan ncoghlan at gmail.com
Mon Jul 12 15:06:27 CEST 2010


On Mon, Jul 12, 2010 at 1:39 PM, Carl M. Johnson
<cmjohnson.mailinglist at gmail.com> wrote:
> I like this idea, but I would tweak it slightly. Maybe we should say
>
> EXPRESSION where:
>    BLOCK
>
> is equivalent to
>
> def _():
>    BLOCK
>    return EXPRESSION
> _()

Implement it that way (or find someone who can), then get back to me* :)

That said, my suggested semantics still have the desired effect in
your use case, since your expression does not contain a name binding
operation, so it makes no difference whether name binding would have
been handled via a return value (your suggestion, which I tried and
failed to implement last time) or via nonlocal name bindings (my
suggestion this time around).

Cheers,
Nick.

*P.S. There's a reason I stopped pushing this idea back then: the
absolute nightmare that was trying to implement it without ready
access to nonlocal variable definitions (trying to figure out what the
return value should be and how it should be unpacked in the
surrounding scope was seriously ugly). Using nonlocal semantics
instead should make it relatively straightforward (fairly similar to a
class definition in fact, although the compilation options for the
nested code object will be different and there'll be a bit of
additional dancing during the symbol pass to figure out any implicit
nonlocal declarations for the inner scope).

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list