[Python-Dev] Static scoping of builtins (Re: Dynamic nested scopes)

Greg Ewing greg@cosc.canterbury.ac.nz
Mon, 06 Nov 2000 16:34:26 +1300 (NZDT)


Guido:

> the lookup in
> globals() can be skipped for builtins, but a local is accessed with
> *zero* dict lookups -- how would you do this while still supporting
> __builtin__.__dict__.open = foo?  have "hookable" dictionaries?

With fully static scoping, I envisage that all three kinds
of scope (local, module and builtin) would be implemented
in essentially the same way, i.e. as arrays indexed by
integers.

That being the case, all you need to do is arrange for the
__builtin__ module and the global scope to be one and the
same thing, and __builtin__.open = foo will work just fine
(assuming open() isn't one of the special inlinable functions).

Getting __builtin__.__dict__['open'] = foo to work as well
may require some kind of special dictionary-like object.
But then you're going to need that anyway if you want to
continue to support accessing module namespaces as if they
are dictionaries.

Whether it's worth continuing to support that in Py3k is
something that can be debated separately.

> integrable procedures (whatever they may be :-)

In the Revised^n Report, some builtin procedures are
declared to be "integrable", meaning that the compiler is
allowed to assume that they have their usual definitions
and optimise accordingly.

(This is quite important in Scheme, even more so than
in Python, when you consider that almost every operation in
Scheme, including '+', is a procedure call!)

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+