Op 2005-10-06, Bengt Richter schreef <[EMAIL PROTECTED]>: > On 5 Oct 2005 09:27:04 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: > >>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. 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 > > IMO you don't really need all that cruft most of the time. E.g., what if ':=' > meant 'assign to variable wherever it is (and it must exist), searching > according > to normal variable resolution order (fresh coinage, vro for short ;-), > starting with > local, then lexically enclosing and so forth out to module global (but not to > builtins).'
Just some ideas about this 1) Would it be usefull to make ':=' an expression instead if a statement? I think the most important reason that the assignment is a statement and not an expression would apply less here because '==' is less easy to turn into ':=' by mistake than into = Even if people though that kind of bug was still too easy 2) What if we reversed the operation. Instead of var := expression, we write expression =: var. IMO this would make it almost impossible to write an assignment by mistake in a conditional when you meant to test for equality. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list