Augument assignment versus regular assignment

Antoon Pardon apardon at forel.vub.ac.be
Mon Jul 17 04:07:04 EDT 2006


On 2006-07-14, Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>> Antoon Pardon <apardon at forel.vub.ac.be> (AP) wrote:
>
>>AP> Well I'll start on an possitive note and accept this. Now I'd like you
>>AP> to answer some questions.
>
>>AP> 1) Do you think the langauge reference makes it clear that this is how
>>AP>    the reader has to understand things.
>
> Yes.
>
>>AP> 2a) In case you answer yes to question (1). Can you explain me how
>>AP>     I have to read the language reference in order to deduce this
>>AP>     is indeed the way things should be understood.
>
> Just read what it says. `It is only evaluated once' is quite clear I would
> say.

If it is so clear, why don't you explain it? 

> Your problem is that you thought __setitem__ is part of evaluation,

No I think the other way around. The evaluation is part of __setitem__ 
In so far as it makes sense to talk about the evaluation of a target
in python

> but it isn't. It is part of assignment,

No the assignment is part of __setitem__

> while __getitem__ is part of evaluation.

How can __getitem__ be part of the evaluation of col['t'] in
a statment like

  col['t'] = 5

The language reference about augmented assigments is not only
talking about evaluating a language element as an expression,
it is also talking about evaluating that language element as
a target. Now I'm not so sure that it makes sense to talk about
evaluating a target in python, but I see no way to avoid that
interpretation in:

  An augmented assignment expression like x += 1 can be rewritten as
  x = x + 1 to achieve a similar, but not exactly equal effect. In
  the augmented version, x is only evaluated once. 

x is only evaluated once in a statement like: x+= 1
This suggests x is evaluated twice in a statement like: x = x + 1
The only way to eavlaute x twice in that statement is that
  x is evaluated once as a target.
So the langauage reference is here talking about (among other things)
evaluating a target.

What the language reference should have said IMO is that in case x
is an attribute reference, index or slicing, the primary expression
will be evaluated only once, as will be the index or slice in the
two latter cases.

This wording doesn't introduce two different kinds of evaluation
as the original wording of the language reference does.

-- 
Antoon Pardon



More information about the Python-list mailing list