Re: "no variable or argument declarations are necessary."
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: "no variable or argument declarations are necessary."

From: Antoon Pardon <apardon@forel.vub.ac.be>
Date: Wed Oct 05 2005 - 12:19:31 CEST

Op 2005-10-05, Duncan Booth schreef <duncan.booth@invalid.invalid>:
> Antoon Pardon wrote:
>
>> It also is one possibility to implement writable closures.
>>
>> One could for instace have a 'declare' have the effect that
>> if on a more inner scope such a declared variable is (re)bound it
>> will rebind the declared variable instead of binding a local name.
>
> That is one possibility, but I think that it would be better to use a
> keyword at the point of the assigment to indicate assignment to an outer
> scope. This fits with the way 'global' works: you declare at (or near) the
> assignment that it is going to a global variable, not in some far away part
> of the code, so the global nature of the assignment is clearly visible.

As far as I understand people don't like global very much so I don't
expect that a second keyword with the same kind of behaviour has
any chance.

> The
> 'global' keyword itself would be much improved if it appeared on the same
> line as the assignment rather than as a separate declaration.
>
> e.g. something like:
>
> var1 = 0
>
> def f():
> var2 = 0
>
> def g():
> outer var2 = 1 # Assign to outer variable
> global var1 = 1 # Assign to global

And what would the following do:

def f():

  var = 0

  def g():

    var = 1

    def h():

      outer var = 2 * var + 1

    h()
    print var

  g()
  print var

f()
Received on Sat Oct 15 04:09:54 2005