7.1. Unqualified Name lookup: the enhanced namespace model

Viper uses a different lookup scheme than python. It does not use the 'two spaces' idea of python, but rather supports lookup in an abstract space called an environment. Environments have methods to get, set, test for the existence of, and delete attributes.

One of the principal changes to Viper made possible by this technology is that full lexical scoping is supported. Functions defined inside functions may contain names which are looked up in the defining environment if they're not found locally. By contrast, python will examine the local context first, and then the module context, ignoring the context of the nested functions definition, namely the local namespace of the enclosing function.

Lexically scoped functions can be passed as arguments and retain linkage to the defining context, that is, full closures are provided.

The global directive has a special role in nested functions. Variables designated global are stored in the enclosing scope, NOT module module scope. This has no effect on top level functions, since the enclosing scope is a module scope. If you wish to bind a module level name in a nested function, you must provide a global directive for the name in _every_ intervening scope, as well as in the function. In other words, global means 'not quite local'.