# [Python-ideas] Keyword same in right hand side of assignments (rev)

Andre Roberge andre.roberge at gmail.com
Tue Mar 17 13:41:42 CET 2009

```On Tue, Mar 17, 2009 at 9:23 AM, <hwpuschm at yahoo.de> wrote:

>
> Thank you very much for correctly remarking that the "definition" I
> formulated contradicts the examples I gave and is therefore utterly
>
> > It is proposed to introduce a Keyword "same",
> > to be used in the right hand side of assignments, as
> > follows:

I once wrote a blog post on how an expression like "N = N + 1" was confusing
to beginners, so I'm sympathetic with the underlying idea.
(http://aroberge.blogspot.com/2005/05/n-n-1.html    Note that there are much
better explanations for naming objects in Python than this old post I
wrote.)

However, I am -1 on this proposal.  IMO, it decreases readability and
achieves very little in terms of clearing up the confusion.

Quick test: which is the easier to read and get right?

n = same + 1
n = sane + 1
n = n + 1

André

>
> >
> >   "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.
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090317/906a5d8c/attachment.html>
```