[Python-Dev] statically nested scopes

M.-A. Lemburg mal@lemburg.com
Wed, 01 Nov 2000 21:51:16 +0100

Jeremy Hylton wrote:
> >>>>> "MAL" == M -A Lemburg <mal@lemburg.com> writes:
>   MAL> [pre-PEP] This will break code... I'm not sure whether it's
>   MAL> worth going down this path just for the sake of being able to
>   MAL> define functions within functions.
> How will this break code?  Any code written to use the scoping rules
> will not work today.
> Python already allows programs to define functions within functions.
> That's not at issue.  The issue is how hard it is to use nested
> functions, including lambdas.

The problem is that with nested scoping, a function defined
within another function will suddenly reference the variables
of the enclosing function as globals and not the module
globals... this could break code.

Another problem is that you can't reach out for the defining
module globals anymore (at least not in an easy way like today).

>   MAL> Wouldn't it be a better idea to somehow add native acqusition
>   MAL> to Python's objects ?
> No.
> Seriously, I don't see how acquistion addresses the same issues at
> all.  Feel free to explain what you mean.

It's not related to *statically* nested scopes, but is to
dynamically nested ones. Acquisition is basically about the
same thing: you acquire attributes from containers. The only
difference here is that the containment relationships are
defined at run-time.
>   MAL> We already have a slot which implements the "contains"
>   MAL> relationship. All we'd need is a way for a contained object to
>   MAL> register itself with the container in a way that doesn't
>   MAL> produce cycles.
> The contains relationship has to do with container objects and their
> contents.  A function's environment is not a container in the same
> sense, so I don't see how this is related.
> As I noted in the PEP, I don't see a compelling reason to avoid
> cycles.

Ok, we have cycle GC, but why create cycles when you don't
have to (Python can also be run without GC and then you'd run
into problems...) ?

Marc-Andre Lemburg
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/