I'm not yet completely sure that arbitrarily nestest namespaces and
symbol resolution is the best general solution. Perhaps a more
"pythonish" solution would be to somehow promote Modules into
something more of a first-class enviromment.
The problem is that when you add Classes and Instances and
inheritance, I'm not always sure what the CORRECT search order
SHOULD be. I was just recently trying to code something that
needed to resolve the default value of a symbol with precedence:
instance-variable
class-variable
module-variable ( i.e. python global )
__main__ module-variable ( Really global )
[ and if STILL not found, use a "hardwired" default value. ]
Forth - another language that has dictionaries at the core of its
implementation, calls it's namespace dictionaries "VOCABULARIES"
and links them together, so search is backwards from the current
dictionary to the "base" dictionary. However, in Forth, this chained
lookup happens at compile time ( interpreter compiling into
threaded-code ) - In Python the symbols are resolved at run time,
so a costly lookup is to be avoided if possible.
Those two points are not necessarily linked.
I'm just groping about for another solution.
- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics