Keyword same in right hand side of assignments (rev)
R. David Murray
rdmurray at bitdance.com
Tue Mar 17 17:12:54 CET 2009
hwpuschm at yahoo.de wrote:
> What I would like is to extend the augmented assignment
> and make it easy to understand for naive readers.
Good luck. :)
> I hope the following literary definition
> is consistent enough to convey the correct meaning:
> "whenever it is possible, modify the target IN PLACE
> according to the right hand side expression.
> If it is not possible to do such a thing,
> substitute the target object with
> an object that is build according to the right hand side expression
> and subsequently deleted"
I don't think that last part is expressing your intent. If you delete
the object you've constructed you've got nothing left for the target to
point to. From what you say later I think you are confusing identifiers
with objects in this text.
> The following examples should be correct:
> "xx = same + 5" synonymous with "xx += 5"
> "value = 2*same + 5" synonymous with "value =*2; value +=5"
> "switch = 1 - same" synonymous with "switch *-1; switch +=1"
> "lst = same + [5,6]" synonymous with "lst += [5,6]"
> "lst = 1/same" synonymous with "lst **=-1"
Your revised intent breaks my expectations of how python's assignment
operator works. At least with += and kin I'm alerted to the fact that
something weird is going on by the fact that the assignment operator
> The following examples would be extensions:
> "lst = [5,6] + same" synonymous with
> "lst.reverse(); lst.extend([6,5]); lst.reverse()"
> "inmutable = same*(same+1)" synonymous with
> "unused=inmutable+1; inmutable*=unused; del unused"
> There seems to be no really simple expression for the above extensions,
> and I take that as an indication
> that the proposed feature could be quite useful.
For the first one, we have:
lst[:0] = [5, 6]
And unless I'm misunderstanding you, the second one is trivially
immutable = immutable*(immutable+1)
I'm afraid I'm -1 on this proposal even without the issue of the keyword.
R. David Murray http://www.bitdance.com
More information about the Python-list