Nested scopes, and augmented assignment

Antoon Pardon apardon at forel.vub.ac.be
Sat Jul 8 15:20:05 EDT 2006


On 2006-07-07, Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>> Antoon Pardon <apardon at forel.vub.ac.be> (AP) wrote:
>
>>AP> On 2006-07-07, Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>>>>> Antoon Pardon <apardon at forel.vub.ac.be> (AP) wrote:
>>>> 
>>AP> Could you maybe clarify what problem we are discussing? All I wrote
>>AP> was that with an assignment the search for the lefthand variable
>>AP> depends on whether the lefthand side is a simple variable or
>>AP> more complicated. 
>>>> 
>>>> What do you mean with `the lefthand variable'? Especially when talking
>>>> about `complicated lefthand sides'?
>
>>AP> The name on the left side of an assignment that refers to a variable,
>>AP> as opposed to names that are attributes.
>
> So let me get it clear:
> In a.b = c, a is the lefthand variable, but b is not?

Yes, b is an attribute of a

> If that is what you mean then I interpret your statement 
>>AP> `with an assignment the search for the lefthand variable
>>AP> depends on whether the lefthand side is a simple variable or
>>AP> more complicated'
>
> as meaning that the search for `a' in `a.b = c' would be different than the
> search for `a' in `a = b'.

It is conceptually different. In the line 'a = b' you don't need to
search for the scope of a. You know it is the current scope, if you
want to know the scope of b on the other hand, you need to search
for statement where it is assigned to.

Sure you can set things up in the interpreter so that the same search
routine is used, but that is IMO an implementation detail.

> Well, it is not. But I can understand the
> confusion. Namely, `a = b' introduces a binding for `a' in the local scope,
> unless `a' was declared global. So the search will find `a' in the local
> scope and it stops there. On the other hand `a.b = c' will not introduce a
> binding for `a'. So the search for `a' may stop in the local space (if
> there was another binding for `a' in the local scope) or it may need to
> continue to outer scopes. The difference, however is not the
> complicatedness of the lefthand side but whether the local scope contains a
> binding for the variable.

The complicatedness of the lefthand side, decided on whether the
variable was introduced in the local scope or not during startup
time. So that complicatedness decided whether the search was
to stop at the local level or not.

-- 
Antoon Pardon



More information about the Python-list mailing list