[Python-ideas] Keyword same in right hand side of assignments (rev)
hwpuschm at yahoo.de
hwpuschm at yahoo.de
Tue Mar 17 13:23:23 CET 2009
Thank you very much for correctly remarking that the "definition" I formulated contradicts the examples I gave and is therefore utterly inadecuate:
> It is proposed to introduce a Keyword "same",
> to be used in the right hand side of assignments, as
> follows:
>
> "xx = same + 5" or "...DELETED..." 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 = [5,6] + same" synonymous with "...DELETED..."
> "lst[2] = 1/same" synonymous with "lst[2] **=-1"
>
> and so on.
What I would like is to extend the augmented assignment
and make it easy to understand for naive readers.
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"
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[2] = 1/same" synonymous with "lst[2] **=-1"
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.
More information about the Python-ideas
mailing list