Re: [Python-3000] Draft PEP for outer scopes

2006-11-04 Thread Ka-Ping Yee
On Thu, 2 Nov 2006, Andrew McNamara wrote:
> >The global scope is the widest scope in which you can declare a variable.
>
> This is inaccurate at best.

No, my statement is correct.  What you are disputing is not what i wrote:

The global scope is the widest scope in which you can declare a variable.

You cannot declare variables in builtin scope in Python.  You can stuff
variables into the builtin module with some manipulation, but it is a
very rare thing to do, it is not encouraged as a normal style of
programming, and it is not supported by the language syntax.

Python, C/C++, JavaScript, Ruby, and Perl all have this in common:

A "global variable" is visible to the entire file and does
not belong to any particular function.

> To be honest, I'm +0 on using "global" in the way GvR proposes. My
> point is that python's globals are already different from other common
> languages, and people cope with that.

That does not constitute an argument in favour of anything.

For example, Python's integers are already different from other common
languages, because they have unlimited range.  That is not a reason to
make "integers" include, say, floating point numbers.


-- ?ing
___
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com


Re: [Python-3000] The meaning of "global variable"

2006-11-04 Thread Ron Adam
Greg Ewing wrote:
> Ron Adam wrote:
> 
>> How about limiting nonlocal to just the immediate parent scope and using 
>> 'parent' as the keyword?
> 
> That could lead to confusing situations. What should
> the following do:
> 
>def f():
>  x = 42
>  def g():
>def h():
>parent x
>x = 88
> 
> Should the assignment to x in h() create a name in
> the scope of g() even though there's no assignment
> in g() to establish that as its home scope? Should
> it be an error?
> 
> --
> Greg

Not confusing at all.  It would work just like global does in the same 
situation.  The parent statement here does not create a name, it only 
designates 
the scope where a name will be written.

I presume you meant:

def f():
  x = 42
  def g():
def h():
  parent x
  x = 88


The x would be a new local x in function g and have no effect on the x in 
function f.  Parent would do exactly what it means in this case, its a 
reference 
to a name in only the parent scope.

Unless you were to do:

def f():
  x = 42
  def g():
parent x
def h():
  parent x
  x = 88

Then all references to x would be the local x in function f.

This is what I meant that it might be possibly to pull a reference down to 
inner 
scopes.  It gives more control on what name space you are writing to and less 
chance of writing to a grandparent scope unintentionally because of a variable 
name being left out, having its name changed, or has been deleted in the 
immediate parent function while editing.

I also don't think this would be too much trouble as nested functions don't 
tend 
to be more than 2 or 3 levels deep very often and if it becomes a problem of 
having too many parent statements, it's probably a good sign a class would be 
better.

IMHO, and if a suitable keyword meaning parent could be found.

   Ron

___
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com