[Python-ideas] Keyword same in right hand side of assignments

Heinrich W Puschmann hwpuschm at yahoo.de
Mon Mar 16 17:37:59 CET 2009

Python-Ideas: Keyword same in right hand side of assignments

It is proposed to introduce a Keyword "same", 
to be used in the right hand side of assignments, as follows: 
  "xx = same + 5" or "xx = 5 + same"  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  "lst = [5,6] + lst" 
  "lst[2] = 1/same" synonymous with  "lst[2] **=-1" 
and so on. 
IN GENERALITY, the effect of keyword same would be the following:
The keyword same should only appear in 
the right hand side expression of an assignment, 
any number of times and wherever a name can appear. 
The left hand side of the assignment would have to be bound to some object. 
The keyword same is substituted by a name, 
which is bound to the object binding the left hand side of the assignment. 
The  expression at the right hand side is evaluated. 
The left hand side identifyer is bound to the result of the expression. 
Since I am not a developer, I have no idea on  
how to difficult or how easy it would be to implement such a feature. 
As a programmer, however, I believe that 
it improves readability and user friendliness, 
and that it fully adjusts to the Python philosophy. 
It is very hard for me to discern,  
whether a similar idea has already been proposed by somebody else.
I did not yet have any useful application for statements like 
  "xx = xx.do(*args)" or  "xx = yy.do(xx,*args)" or "xx = xx.do(xx,*args)" 
but as a matter of generalization, they should also allow subtitution 
of the right hand side appearances of xx by the keyword same.  
Heinrich Puschmann, Ulm



More information about the Python-ideas mailing list