nested scopes
D-Man
dsh8290 at rit.edu
Tue Feb 6 09:44:53 EST 2001
On Mon, Feb 05, 2001 at 06:57:56PM +0000, Jeremy Hylton wrote:
| In article <mailman.981395193.31631.python-list at python.org>,
| D-Man <dsh8290 at rit.edu> wrote:
[snip]
|
| No. Nested scopes don't require you to do anything different unless you
| actually use nested scopes. In places where Java would raise a
| compile-time error because it can't tell if a name will be used
| unitialized, Python will not complain at comile time. Instead, it will
| raise a NameError if an error occurs at run time. I won't offer any
| opinions about which is better.
Hmm, ok. I think I need to learn more details of how this nested
scope change affects the rules/semantics of python.
|
| > I think it is acceptable if variables like loop counters and temps
| > inside a loop don't exist in the function's namespace. ie:
|
| Regardless of whether you find it acceptable, the language doesn't work
| that way.
I just thought that that might have been something the nested scopes
would have changed. I was letting you know I won't complain if that
change happens, though I'm not requesting it either :-).
I think that maybe my experience with C/C++/Java isn't helping me
here. Those languages have nested scopes and variables declared in
such a scope disappear outside that scope. This makes sense. I guess
the difference is that a loop/if/try block defines a scope in
C/C++/Java but doesn't in Python. This is probably where I got
confused.
|
| > Last quarter I took a class called "Programming Language Concepts"
| > that discussed the design of programming languages. It was the first
| > time I had heard of dynamic scoping. (Actually, I think I saw it
| > mentioned in a lisp context, but I didn't know what it meant) The
| > professor didn't know of any situations where it would be
| > advantageous, and I couldn't contrive any either. I was kind of
| > surprised when I heard python described as "dynamically scoped"
| > because its scoping was really quite natural for me. The [23]-level
| > scoping makes the dynamic scoping almost static and I don't see that
| > as a weakness.
|
| Python's scoping rules aren't dynamic, never have been. (At least not
| as long as I've been using the language.) It used to be that scopes
| didn't nest, but that doesn't make scoping dynamic.
I thought I heard someone say that python's scoping rules are (prior
to 2.1a1, that is) dynamic.
|
| >
| > I really don't know, at this moment, whether adding nested static
| > scopes will strengthen or weaken the language.
|
| PEP 227 has a brief discussion of some benefits, among them that lambdas
| are easier to use. http://python.sourceforge.net/peps/
I think I ought to read that in more detail, and probably read up on
the accepted definitions of some terms.
Thanks for the reply.
-D
More information about the Python-list
mailing list