Parallel Assignment
January 11, 2019
Recently, I was writing a program where I needed parallel assignment; the details of my program don’t matter. Some languages provide parallel assignment natively; for instance, Python:
Python 2.7.13 (default, Mar 13 2017, 20:56:15) [GCC 5.4.0] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> a,b,c = 1,2,3 >>> print a,b,c 1 2 3 >>> a,b,c = b,c,a >>> print a,b,c 2 3 1
You can do something similar in C (I think — I’m not sufficiently expert in C to be certain this works):
#define SWAP(x, y) { typeof(x) t = x; x = y; y = t }
Your task is to add parallel assignment to your favorite programming language. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.