Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)

Ron Adam rrr at ronadam.com
Tue Aug 9 22:16:16 EDT 2005


seberino at spawar.navy.mil wrote:
> I've heard 2 people complain that word 'global' is confusing.
> 
> Perhaps 'modulescope' or 'module' would be better?
> 
> Am I the first peope to have thought of this and suggested it?
> 
> Is this a candidate for Python 3000 yet?
> 
> Chris


After reading though some of the suggestions in this thread, (but not 
all of them), how about something a bit more flexible but not too different.

For python 3000 if at all...

Have the ability to define names as shared that only live while the 
function that declared them has not exited.

The new statements could be called *share* and *shared*.

     def boo():
         shared x,y,z	# Used names predefined in shared name space.
         return x+1,y+2,z+3	

     def foo():
         x,y,z = 1,2,3
         share x,y,z     # These would be visible to sub functions
                         # but not visible to parent scopes once the
                         # function ends. [*1]

         boo()           # modify shared x,y and z in foo.


[*1.]  Unless they have also declared the same names as share. (See below.)

'Share' is used to define names to be visible in child scopes, and 
'shared' allows access to shared names declared in parent scopes.

Having too keywords is more explicit, although this may work with a 
single key word pretty much as it does now.

A single shared name space would still be used where 'share' adds names 
to be 'shared' and those names are deleted when the function that 
declared them exits.  They don't need to live past the life of the 
function they were first declared in.

In recursive functions, (or when a name is reshared), declaring a name 
as shared could just increment a reference counter, and it wouldn't be 
removed from shared until it reaches zero again.

Using 'share' twice with the same name in the same function should cause 
an error.  Using 'shared' with a name that is not in shared name space 
would cause an error.


Just a few thoughts.

Cheers,
Ron




	
















More information about the Python-list mailing list