Postfix/Prefix Operators (++,--)

Peter Hansen peter at engcorp.com
Fri Jun 6 13:38:36 EDT 2003


Joshua Marshall wrote:
> 
> Peter Hansen <peter at engcorp.com> wrote:
> ...
> >> ++/-- can be added to Python, and could act in a way that wouldn't
> >> surprise C or Java programmers.  There really isn't any conceptual
> >> difference between references to immutabe ints and C/Java primitive
> >> ints.
> 
> > How would the error generated when the C or Java programmer wrote
> > the following code not surprise him or her?
> 
> >   c = 1
> >   a = c++
> 
> I wouldn't design ++ to error in this case:
> 
>   >>> c = 1
>   >>> a = c++
>   >>> a
>   1
>   >>> c
>   2

Except that that violates a fundamental aspect of Python, which while
I can't describe it in the best technical terms as I don't ever work 
at the compiler level, could be said as "you are rebinding a name (c)
without using an assignment statement".  I'm not sure whether there
is ever a case where this is true in regular Python, and I suspect
that if you were to attempt to implement this, it would require 
fundamental changes that would make Python not Python...  so I'm still
confident there's "no chance of having it, and no reason to have it."

-Peter




More information about the Python-list mailing list