Re: Augument assignment versus regular assignment

2006-07-20 Thread Antoon Pardon
On 2006-07-19, Terry Reedy [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] So IMV those preparation before the attachment, belong to whatever the interpreter does before it actually attaches an object to a name/slot. So the evaluation of

Re: Augument assignment versus regular assignment

2006-07-20 Thread Terry Reedy
Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 2006-07-19, Terry Reedy [EMAIL PROTECTED] wrote: But I won't. The amount of duplication that can be factored out with augmented assignment depends on the granularity of operations. I can agree with that. But until

Re: Augument assignment versus regular assignment

2006-07-19 Thread Antoon Pardon
On 2006-07-18, Terry Reedy [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 2006-07-17, Terry Reedy [EMAIL PROTECTED] wrote: Or, whether docs (and reasonable interpretation thereof) and implementation match, which I claim they do it this

Re: Augument assignment versus regular assignment

2006-07-19 Thread Boris Borcic
Antoon Pardon wrote: The language reference doesn't talk about objects. And IMO you should be carefull if you want to use the word object here. In the line: foo += 1, you can't talk about the object foo, since foo will possibly be bound to a different object after the assignment than it

Re: Augument assignment versus regular assignment

2006-07-19 Thread Terry Reedy
Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Try some personal introspection. When you act as a Python interpreter, what do you do? I do the evaluation of the target in the __setitem__ method (or the STORE_SUBSCR opcode). I meant mentally, in your mind ;-)

Re: Augument assignment versus regular assignment

2006-07-18 Thread Antoon Pardon
On 2006-07-17, Piet van Oostrum [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] (AP) wrote: AP On 2006-07-14, Piet van Oostrum [EMAIL PROTECTED] wrote: Just read what it says. `It is only evaluated once' is quite clear I would say. AP If it is so clear, why don't you explain it?

Re: Augument assignment versus regular assignment

2006-07-18 Thread Antoon Pardon
On 2006-07-17, Paul Boddie [EMAIL PROTECTED] wrote: Antoon Pardon wrote: 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.

Re: Augument assignment versus regular assignment

2006-07-18 Thread Antoon Pardon
On 2006-07-17, Terry Reedy [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 2006-07-15, Terry Reedy [EMAIL PROTECTED] wrote: The problem with understanding augmented assignment is that it directs the compiler and interpreter to do one or

Re: Augument assignment versus regular assignment

2006-07-18 Thread Paul Boddie
Antoon Pardon wrote: Now maybe I'm just not bright enough, so maybe you can explain what something like col['t'] is evaluated to in a statement like: col['t'] = exp In the notation given earlier, let us say that it would be this: namespace = col setitem(namespace, t, exp) Note that in my

Re: Augument assignment versus regular assignment

2006-07-18 Thread Terry Reedy
Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 2006-07-17, Terry Reedy [EMAIL PROTECTED] wrote: Or, whether docs (and reasonable interpretation thereof) and implementation match, which I claim they do it this case. The claim, in reference to the CPython

Re: Augument assignment versus regular assignment

2006-07-18 Thread Piet van Oostrum
Antoon Pardon [EMAIL PROTECTED] (AP) wrote: AP On 2006-07-17, Piet van Oostrum [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] (AP) wrote: AP On 2006-07-14, Piet van Oostrum [EMAIL PROTECTED] wrote: Just read what it says. `It is only evaluated once' is quite clear I would say.

Re: Augument assignment versus regular assignment

2006-07-17 Thread Antoon Pardon
On 2006-07-14, Piet van Oostrum [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] (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 APthe reader

Re: Augument assignment versus regular assignment

2006-07-17 Thread Antoon Pardon
On 2006-07-15, Terry Reedy [EMAIL PROTECTED] wrote: The problem with understanding augmented assignment is that it directs the compiler and interpreter to do one or maybe two mostly invisible optimizations. To me, the effective meaning of 'evalutating once versus twice' is most easily

Re: Augument assignment versus regular assignment

2006-07-17 Thread Paul Boddie
Antoon Pardon wrote: 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. I think the difficulty here for the author of this

Re: Augument assignment versus regular assignment

2006-07-17 Thread Piet van Oostrum
Antoon Pardon [EMAIL PROTECTED] (AP) wrote: AP On 2006-07-14, Piet van Oostrum [EMAIL PROTECTED] wrote: Just read what it says. `It is only evaluated once' is quite clear I would say. AP If it is so clear, why don't you explain it? I have done that in another thread. Your problem is that

Re: Augument assignment versus regular assignment

2006-07-17 Thread Terry Reedy
Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 2006-07-15, Terry Reedy [EMAIL PROTECTED] wrote: The problem with understanding augmented assignment is that it directs the compiler and interpreter to do one or maybe two mostly invisible optimizations. To me,

Re: Augument assignment versus regular assignment

2006-07-17 Thread Terry Reedy
Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 2006-07-15, Terry Reedy [EMAIL PROTECTED] wrote: The problem with understanding augmented assignment is that it directs the compiler and interpreter to do one or maybe two mostly invisible optimizations. To me,

Re: Augument assignment versus regular assignment

2006-07-15 Thread Piet van Oostrum
Gerhard Fiedler [EMAIL PROTECTED] (GF) wrote: GF On 2006-07-14 16:07:28, Piet van Oostrum wrote: 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

Re: Augument assignment versus regular assignment

2006-07-14 Thread Piet van Oostrum
Antoon Pardon [EMAIL PROTECTED] (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 APthe reader has to understand things. Yes. AP 2a) In case you

Re: Augument assignment versus regular assignment

2006-07-14 Thread Gerhard Fiedler
On 2006-07-14 16:07:28, Piet van Oostrum wrote: 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'

Re: Augument assignment versus regular assignment

2006-07-14 Thread Terry Reedy
The problem with understanding augmented assignment is that it directs the compiler and interpreter to do one or maybe two mostly invisible optimizations. To me, the effective meaning of 'evalutating once versus twice' is most easily seen in the byte code generated by what is, remember, the

Re: Augument assignment versus regular assignment

2006-07-12 Thread Antoon Pardon
On 2006-07-11, Piet van Oostrum [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] (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

Re: Augument assignment versus regular assignment

2006-07-11 Thread Antoon Pardon
On 2006-07-10, Terry Reedy [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I disagree. The += version only evaluates the index once, but still has to find the object twice. No it does not *have* to find the object twice and no it does *not*

Re: Augument assignment versus regular assignment

2006-07-11 Thread Piet van Oostrum
Antoon Pardon [EMAIL PROTECTED] (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

Re: Augument assignment versus regular assignment

2006-07-10 Thread Antoon Pardon
On 2006-07-09, Fredrik Lundh [EMAIL PROTECTED] wrote: Frank Millman wrote: So it looks as if x += [] modifies the list in place, while x = x + [] creates a new list. objects can override the += operator (by defining the __iadd__ method), and the list type maps __iadd__ to extend. other

Re: Augument assignment versus regular assignment

2006-07-10 Thread Jim Segrave
In article [EMAIL PROTECTED], Antoon Pardon [EMAIL PROTECTED] wrote: On 2006-07-09, Fredrik Lundh [EMAIL PROTECTED] wrote: Frank Millman wrote: So it looks as if x += [] modifies the list in place, while x = x + [] creates a new list. objects can override the += operator (by defining the

Re: Augument assignment versus regular assignment

2006-07-10 Thread Antoon Pardon
On 2006-07-10, Jim Segrave [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Antoon Pardon [EMAIL PROTECTED] wrote: On 2006-07-09, Fredrik Lundh [EMAIL PROTECTED] wrote: Frank Millman wrote: So it looks as if x += [] modifies the list in place, while x = x + [] creates a new list.

Re: Augument assignment versus regular assignment

2006-07-10 Thread Terry Reedy
Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I disagree. The += version only evaluates the index once, but still has to find the object twice. No it does not *have* to find the object twice and no it does *not* find the object twice. From the viewpoint of the

Re: Augument assignment versus regular assignment

2006-07-09 Thread Frank Millman
nagy wrote: Thanks, Kirk. I considered the += as only a shorthand notation for the assignment operator. Since for lists + is simply a concatetation, I am not sure it x=x+[2] is creating a brand new list. Could you refer me to any documentation on this? Thanks, Nagy My habit is to check

Re: Augument assignment versus regular assignment

2006-07-09 Thread Kirk McDonald
Frank Millman wrote: nagy wrote: Thanks, Kirk. I considered the += as only a shorthand notation for the assignment operator. Since for lists + is simply a concatetation, I am not sure it x=x+[2] is creating a brand new list. Could you refer me to any documentation on this? Thanks, Nagy My

Re: Augument assignment versus regular assignment

2006-07-09 Thread Fredrik Lundh
Frank Millman wrote: So it looks as if x += [] modifies the list in place, while x = x + [] creates a new list. objects can override the += operator (by defining the __iadd__ method), and the list type maps __iadd__ to extend. other containers may treat += differently, but in-place

Re: Augument assignment versus regular assignment

2006-07-08 Thread nagy
Thanks, Kirk. I considered the += as only a shorthand notation for the assignment operator. Since for lists + is simply a concatetation, I am not sure it x=x+[2] is creating a brand new list. Could you refer me to any documentation on this? Thanks, Nagy Kirk McDonald wrote: nagy wrote: I do the

Re: Augument assignment versus regular assignment

2006-07-08 Thread Chris Lambacher
Looks like x=x+[2] creats a new list to me: b = [8,5,6] x = b x = x + [2] print b,x [8, 5, 6] [8, 5, 6, 2] -Chris On Sat, Jul 08, 2006 at 11:56:11AM -0700, nagy wrote: Thanks, Kirk. I considered the += as only a shorthand notation for the assignment operator. Since for lists + is simply a

Re: Augument assignment versus regular assignment

2006-07-08 Thread Kirk McDonald
nagy wrote: Thanks, Kirk. I considered the += as only a shorthand notation for the assignment operator. Since for lists + is simply a concatetation, I am not sure it x=x+[2] is creating a brand new list. Could you refer me to any documentation on this? Yes:

Augument assignment versus regular assignment

2006-07-07 Thread nagy
I do the following. First create lists x,y,z. Then add an element to x using the augumented assignment operator. This causes all the other lists to be changed also. But if I use the assignment x=x+[4] instead of using the augumented assignment, the y and z lists do not change. Why is that? This

Re: Augument assignment versus regular assignment

2006-07-07 Thread Kirk McDonald
nagy wrote: I do the following. First create lists x,y,z. Then add an element to x using the augumented assignment operator. This causes all the other lists to be changed also. But if I use the assignment x=x+[4] instead of using the augumented assignment, the y and z lists do not change.