Augmented Assignement (was: Re: PEP scepticism)

Paul Prescod paulp at ActiveState.com
Mon Jul 2 13:44:35 EDT 2001


Alex Martelli wrote:
> 
> "Paul Prescod" <paulp at ActiveState.com> wrote in message
> news:mailman.994083124.18397.python-list at python.org...
>     ...
> > I'd like to see some real-world code that takes advantage of the fact
> > that this single operator behaves differently with mutable and immutable
> > types. Then I will believe that it isn't just a squishing together of
> > two unrelated features.
> 
> Depending on how you define "real world", I have some use of that
> with my still-unreleased "in-house" (literally:-) "gmpy 1.0", where I
> have mutable numbers.  

That's pretty weird but I have no objection to consenting adults doing
weird things. I would suggest you consider lightweight proxies instead
of mutable numbers so that you get optimization for x = x + y "for
free".

But let me try another tact: what if we just changed the behavior of
lists. Rather than saying "mutable objects do this, immutable objects do
that", I would like to say "built-in, ordinary, typical objects do this,
rare, advanced, specialized objects do that."

"This" is the simplest interpretation x +=y is equivalent to x = x + y.

"That" is the more sophisticated polymorphic interpretation where the
type chooses its own behaviour.

Would this be an acceptable compromise? Everyone wins.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list