explicit variable scoping
Sean Ross
sross at connectmail.carleton.ca
Tue Mar 23 11:19:18 EST 2004
"Eyal Lotem" <gnupeaker at yahoo.com> wrote in message
news:mailman.279.1080051991.742.python-list at python.org...
> Explicit "let"s do seem to get rid of the
> local-vs-global issue, while providing an elegant
> solution to the nested-functions variable access
> problems.
>
> d=1
> e=9
> def f():
> def a=None,b=3 # Since locals are typically
> # created via an assignment
> # it makes much sense to allow
> # unifying the creation of their
> # scope [def] with the assignment
> # to eliminate some redundancy
> b=4 # rebinding
> d=5 # raise error, neither local or global
> global e
> def g():
> e=10 # global assignment
> b=5 # rebinding
> def a=7 # new local binding
> print a, b, e # will print None, 5, 10
Hi.
Re-using "def" like that really is confusing. Maybe try "let":
let d = 1
let e = 9
def f():
let a, b = None, 3
b = 4 # rebind
d = 5 # raise error, should be "let d = 5"
def g():
e = 10 # global assignment
b = 5 # rebind b in f
let a = 7 # new local binding
print a, b, e # will print None 5 10
Or, perhaps ":=" :
d := 1
e := 9
def f():
a, b := None, 3
b = 4 # rebind
d = 5 # raise error, should be "d := 5"
def g():
e = 10 # global assignment
b = 5 # rebind b in f
a := 7 # new local binding
print a, b, e # will print None 5 10
More information about the Python-list
mailing list