namespaces in eval(): spot error in 3 line program

Terry Reedy tjreedy at udel.edu
Wed May 25 15:02:06 EDT 2005


"pasa" <harri.pasanen at trema.com> wrote in message

> Do functions carry their own pointer to global namespace,
> which gets defined at function compile time, or what is
> happening here?

To expand on Just's answer:

For lexical scoping --  resolution of globals in the definition context --  
some reference to that context is required.  The alternative of dynamic 
scoping -- resolution of globals in the calling context -- has been tried 
in other languages and found wanting.  For instance, if you call a function 
in the math module that uses pi, sin, or cos, one almost certainly wants it 
to use the object defined and bound to pi, sin, or cos in the math module. 
That happens automatically with lexical scoping.  With dynamic scoping, one 
would have to do 'from math import *' first.  And so on for everything 
else.

Terry J. Reedy






More information about the Python-list mailing list