Postfix/Prefix Operators (++,--)

John Roth johnroth at ameritech.net
Fri Jun 6 19:51:40 EDT 2003


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3EE0D19C.7D7FFCA0 at engcorp.com...
> 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."

Well, let's see. The "def", "class" and "import" statements all (re)bind
names. So do several of the builtin functions (setattr() comes to mind
immediately.)

On the other hand, I don't think there's a valid use case for it.

John Roth

John Roth
>
> -Peter






More information about the Python-list mailing list