Augument assignment versus regular assignment

Antoon Pardon apardon at forel.vub.ac.be
Wed Jul 12 04:54:56 EDT 2006


On 2006-07-11, Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>> Antoon Pardon <apardon at forel.vub.ac.be> (AP) wrote:
>
>>AP> As I read the language reference the x stands for a target expression.
>>AP> Now what does it mean to evaluate a target expression like col[key].
>>AP> IMO it means finding the location of the item in the collection: the
>>AP> bucket in the directory, the node in the tree ... grosso mode it
>>AP> boils down to the call to __setitem__ or __getitem__ depending
>>AP> on where the col[key] was located in the line (or if you prefer
>>AP> the view from the interpreter it boils down to the BINARY_SUBSCR
>>AP> and STORE_SUBSCR opcodes).
>
>>AP> So if the language reference seems to implies that col[key] will
>>AP> only be evaluated once in a line like: "col[key] += 1" I expect
>>AP> only one call from __setitem__ or __getitem__ (or only one
>>AP> from BINARY_SUBSCR or STORE_SUBSCR)
>
> You need both the __setitem__ and the __getitem__ otherwise it won't work.
> I think the "evaluated once" clause is for cases like:
>
> f(a)[g(b)] += 1
>
> where f and/or g have side effects. These side effects should then take
> place only once. Side effects in __setitem__ and __getitem__ is not what it
> is talking about.

Well I'll start on an possitive note and accept this. Now I'd like you
to answer some questions.

1) Do you think the langauge reference makes it clear that this is how
   the reader has to understand things.

2a) In case you answer yes to question (1). Can you explain me how
    I have to read the language reference in order to deduce this
    is indeed the way things should be understood.

2b) In case you anser no to question (1). Do you find it unreasonable
    that I ask that the language reference would be rewritten here so
    that your explanation can be (more easily) deduced from it.

-- 
Antoon Pardon



More information about the Python-list mailing list