[Python-ideas] Allow using ** twice

Peter Jung ilmiacs at gmail.com
Thu Jun 6 21:56:32 CEST 2013



Am 06.06.2013 um 21:36 schrieb "Vernon D. Cole" <vernondcole at gmail.com>:

> 
> On Thu, Jun 6, 2013 at 12:47 PM, <python-ideas-request at python.org> wrote:
>> 
>> Does it? All the languages which only allow += on immutable values (e.g.
>> Java, C, Javascript) obviously don't mutate anything.
> 
> Eh?   It's been twenty years or so since I programmed C for a living, but I seem to remember that a C variable is actually only a handy label for a memory location, and that therefore *everything* is mutable -- even when it shouldn't be. And += was invariably implemented in machine language by a two-argument add straight to that memory location.  Some of the early C compilers would even allow you to use a literal on the left side, like "2 += 3"  which would change the value of the literal '2' to become five.   Made for some interesting bugs!  
> 

Agreed 100%

> Ignoring all of that,  if + worked on dictionaries, I would expect that duplicate keys would receive the value from the right-hand argument,

this in fact would be the only order consistent with the evaluation order defined in python: A+B+C is interpreted as (A+B)+C, always. 


> and that the operation would create a new dictionary.  (and I think it would be a great +1 idea.)

I disagree. With

C=A
A+=B

I'd expect A==C still to be true, whatever B would be. This is how all nonatomic types in python behave (the symbol is just a pointer) and a dict is not atomic by any means. 



> --
> Vernon Cole
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130606/bd3f668a/attachment.html>


More information about the Python-ideas mailing list