Augmented Assignement (was: Re: PEP scepticism)
Paul Prescod
paulp at ActiveState.com
Mon Jul 2 18:24:39 EDT 2001
Alex Martelli wrote:
>
>...
>
> Care to expand on this...? Say that x is (a lightweight proxy holding)
> a Python long of a few hundred digits which is counting the number
> of occurrences of some event-classification in a space of events that
> is pretty huge because of combinatorial-explosion. y is another count
> I have to add to x, typically a few hundred thousands or a few millions
> at most. How would x and y being lightweight proxies save me any
> computational effort?
I shouldn't have said to use proxies instead of mutable integers. I
meant that you should have proxy x holding mutable integer x' and proxy
y holding mutable integer y'. Then when you see x+y you can mutate x
because you claim that you know that there is only ever one reference to
these objects. That doesn't rely on the person using a particular syntax
for adding to x.
>...
> I don't understand whether you're arguing in the abstract, or concretely
> proposing to break any Python program, written in the last year or so,
> which decided to code "mylist += somemore" as opposed to coding
> "mylist.extend(somemore)" while some other reference to mylist may
> be outstanding. If the latter, I don't see how such code breakage may
> be "a compromise".
It preserves your ability to use += to define "integer mutation" without
making common Python usage more complicated.
> .... In the abstract, if you were designing a new language
> from scratch and wanted to have both mutable and immutable datatypes
> in it, I guess you could draw the line for a switchover in +='s behavior at
> different thresholds; mutable vs immutable is very easy to draw, 'ordinary'
> vs 'advanced' may not be, but maybe in such a hypothetical language
> you might have other ways to easily flag ordinary vs advanced data
> types so people cannot get confused. ...
How do we "flag" types that have in-place behavior now? How would I
recognize that your integers were mutable based on anything other than
reading the documentation or code?
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.ActiveState.com/pythoncookbook
More information about the Python-list
mailing list