[Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes)

Steven Bethard steven.bethard at gmail.com
Thu Feb 23 17:19:08 CET 2006


On 2/22/06, Almann T. Goo <almann.goo at gmail.com> wrote:
> Since the current semantics allow *evaluation* to an enclosing scope's
> name by an "un-punctuated" name, "var" is a synonym to ".var" (if
> "var" is bound in the immediately enclosing scope).  However for
> *re-binding* to an enclosing scope's name, the "punctuated" name is
> the only one we can use, so the semantic becomes more cluttered.
>
> This can make a problem that I would say is akin to the "dangling else problem."
>
>     def incrementer_getter(val):
>        def incrementer():
>            val = 5
>            def inc():
>                ..val += 1
>                return val
>            return inc
>        return incrementer
>
> Building on an example that Steve wrote to demonstrate the syntax
> proposed, you can see that if a user inadvertently uses the enclosing
> scope for the return instead of what would presumably be the outer
> most bound parameter.  Now remove the binding in the incrementer
> function and it works the way the user probably thought.

Sorry, what way did the user think?  I'm not sure what you think was
supposed to happen.

STeVe
--
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy


More information about the Python-Dev mailing list