In defence of the two-namespace rule
Phil Jensen
pjensen at columbus.rr.com
Thu Jan 20 23:20:00 EST 2000
Edward Welbourne <eddyw at lsl.co.uk> wrote, inter alia:
> Define a function, foo, which returns a function it has defined, as bar,
> during its suite; have bar refer to some of the local variables of foo.
> With lexical scoping, the interpreter is obliged to keep the namespace
> foo used (on that invocation) for as long as anyone retains a reference
> to what it returned.
I'm newish enough not to know to what extent the lexical scoping
advocates regard closures as crucial. From a language-design
standpoint the two issues are separable, however. For example,
the (lexically-scoped) Modula-3 reference says:
| A local procedure can be passed as a parameter but not
| assigned, since in a stack implementation a local procedure
| becomes invalid when the frame for the procedure containing
| it is popped.
Personally, I agree with Edward (and many others) that the two-scope
rule harmonizes well with Python. Lexical scoping seems to play
better in a language with declarations.
Phil
More information about the Python-list
mailing list