Post-assignment operator ?

Jorge Chamorro jorge at
Sun Sep 5 10:42:45 PDT 2010

I've had the need to read and save an array element just before updating it to a new value:

oldValue= array[index];
array[index]= newValue;

If instead I had had to post-increment/decrement it I could have written just :

doSomethingWith( array[index]++ );

which is shorter, clearer, and does not need any temp. var.

So, my question/idea/proposal (I hope it's not too dumb) is, why not to create a "post-assignment" operator ? One that given the expression:

`aReference *postAssignmentOperator* newValue` would assign newValue to aReference but would return the value that it had before the assignment.

doSomethingWith( array[index] := newValue );

It may serve too to swap(a, b) :

a= ( b:= a )


More information about the es-discuss mailing list