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 )
?
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;
doSomethingWith(oldValue)
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 )
?
--
Jorge.
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; doSomethingWith(oldValue)
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 )
?