Topic: More Logical Assignment Operators


Author: garyp@manutius.UUCP (Gary Powell)
Date: 20 Jul 92 14:59:30 GMT
Raw View
It has occured to me that if we "add" the operators &&= and ||=
then we should also add all of the other logical test operators as well
or else we are leaving more holes in the language.

1)   >==              // Greater than assignment
  Where    x >== y    <==>  x = x > y

2)   <==              // Less than assignment
  Where    x <== y    <==>  x = x < y

3)   >===              // Greater than or equal to assignment
  Where    x >=== y    <==>  x = x >= y

4)   <===              // Less than or equal to assignment
  Where    x >=== y    <==>  x = x <= y

5)   !==              // Logical not assignment
  Where    x !== y    <==>  x = !x

6)   !===              // Not equal to assignment
  Where    x !=== y    <==>  x = x != y

7)   ~==              // one's complement assignment
  Where    x ~== y    <==>  x = ~x

Of course it isn't required to have all of these operators do these particular
idioms.

One thought comes to mind and that is to use these to do the common, test
and assign of the value.

ie:
  For operator   x >== y  translate to

  if (x >= y)
  {
     x = y;
  }

  Or the more general rule of
  x (compare to) y
  if the comparsion fails assign to x the value in y.

Again, since none of the above are legal C or C++ code the addition of these
shortcut operators won't break any code.

Now wasn't that fun?
    -Gary-

Gary Powell ------------+ Internet:     garyp@aldus.com
c/o Aldus Corporation   | uunet:        manutius!garyp@uunet.uu.net
411 1st Ave South       | uucp:         camco!manutius!garyp
Seattle, WA 98104  USA  | Voice:        (206) 622-5500