In this case, f would use the global declaration of a . Nearly all languages use lexical scope. Under dynamic scope rules, variables are identified by looking backwards through the program execution to find the most recently executed declaration. In this case, f would use the local declaration of a within g . Early versions of LISP and some scripting languages use dynamic scope.
Dynamic scope makes procedures act like macros.
In Pascal, Ada, ML, etc., we can nest procedure declarations inside other procedure declarations. More precisely, the variables associated with the most recent still-live activation of the outer procedure are visible within inner procedures. In most languages, if procedure f is declared inside g , then f can only appear as descendent of g in the activation tree. In most languages, procedures themselves are potentially recursive, so their names are visible within their own bodies. Environment chaining To find non-local variables on the stack while executing procedure f , it suffices to know the environment that was in place when the declaration of f was encountered.