One last shot at the Augmented Assignment PEP
Grant Edwards
ge at nowhere.none
Thu Sep 14 13:52:58 EDT 2000
In article <ObVv5.153507$6y5.98753496 at news2.rdc2.tx.home.com>, Rainer Deyke wrote:
>"Huaiyu Zhu" <hzhu at users.sourceforge.net> wrote in message
>news:slrn8s04pv.9on.hzhu at rocket.knowledgetrack.com...
>> How about using = for assignment and ! for augmentation?
>>
>> a = b = []; a += [1] # a==[1] and b==[]
>> a = b = []; a +! [1] # a==[1]==b
>>
>> a = b = (); a += (1,) # a==(1,) and b==()
>> a = b = (); a +! (1,) # Error, () is immutable.
>
>This makes sense to me.
I agree. I would expect the following to be equivalent. Always.
a = a + b
a += b
If they are sometimes equivalent and sometimes not, it seems to
me to violate the "rule of least surprises."
I'd vote for two sets of operators: one that is always an
assignment, and one that is always an in-place modification of
a mutable object. [Though it seems we're arguing a moot
question once again.]
I think it looks better the other way around:
a !+ b rather than a +! b
(I've too much C wiring in my brain and read the latter as a +
!b, but that's just me.)
But, "!+" would be inconsistent with "+=".
I like the "!" though, it's reminiscent of the "!" character
often used as a hint in the names of Scheme functions who
modified an object rather than just being "functional".
--
Grant Edwards grante Yow! Do I have a lifestyle
at yet?
visi.com
More information about the Python-list
mailing list