One last shot at the Augmented Assignment PEP

Steve Holden sholden at holdenweb.com
Thu Sep 14 16:22:16 EDT 2000


Grant Edwards wrote:
> 
> In article <8pous80tul at news1.newsguy.com>, Alex Martelli wrote:
> 
> >Without the polymorphism over mutable objects wrt immutable
> >ones, += and its ilk would be mere syntactic sugar of no big
> >real interest.  WITH the polymorphism, they become a precious
> >innovation.  Call them "mutation-suggestors with fallback to
> >rebinding if the object is immutable", if you wish, because
> >that is what they are.
> 
Well actually, Alex, there's more than syntactic sugar in what we
might call a simple assignment.  I'd be prepared to have the "lvalue"
(as we might call it) evaluated only once, allowing optimization of
expressions like:

	something.incredibly[unbelievably](complex) = \
	something.incredibly[unbelievably](complex) + 1

to
	something.incredibly[unbelievably](complex) += 1

even if side-effects were not duplicated. I'm just not sure whether this
strengthens my case or weakens it :-(  and I *know* this isn't going to
make any difference to the forthcoming implementations.

> This leads into the an new field:
> 
>             programming via suggestions and hints
> 
> I suppose if you really want assignment you can do it
> explicitly with the old syntax.  If you know that you really
> want mutation, you can use the method call to make it explicit.
> That way you get the proper error if you try to mutate an
> immutable object.
> 
> --
> Grant Edwards                   grante             Yow!  My FAVORITE group
>                                   at               is "QUESTION MARK & THE
>                                visi.com            MYSTERIANS"...

Well, doing it explicitly with the old syntax is going to be my solution
of choice.  But then I've already confessed to being a bear of very little
brain.  I just hope the documentation makes it quite clear, both to
newbies and C/C++ programmers, that the semantics of the new augmented
assignment operators are not equivalent to the "old syntax".

regards
 Steve
-- 
Helping people meet their information needs with training and technology.
703 967 0887      sholden at bellatlantic.net      http://www.holdenweb.com/





More information about the Python-list mailing list