[comp.lang.c] Concurrent assingment

dankg@earthquake.Berkeley.EDU (Dan KoGai) (06/28/90)

In article <1990Jun28.143410.6171@cs.utk.edu> wozniak@utkux1.utk.edu (Bryon Lape) writes:

>	I finally came to the realization that C needs a concurrent
>assignemnt statement.  

Why?

>The syntax would be like the following:
>
>	x,y,z = 1,2,3;
>
>	which would make x=1, y=2, and z=3.  This would also be used to
>swap values, such as:

	First this can be achieved by x = 1; y = 2; z = 3;  Second this
makes C compiler far more comlex because first it has to check the
number of assignments and second , in C is also used to as an operator
that often appear as int x, y, z = 1; in this case only z is explicity
initialized.
	
>	x,y = y,x;
>	This would be equivalent to the following:
>	  z = x;
>	  x = y;
>	  y = z;
>
>

	But in implementation it cannot go like x = y; y = x because
old x value is discarded in first assignment.  It has to store old
value of second variable somewhere.  and swap(x,y) looks simpler and
swap never requres compiler to check the number of assignments.

	You still haven't explained why it's NEEDED. You just show
its pros but it has far more cons than pros.  if you still doubt it,
try the following case:

	x, y = (x, y = y, x), (x, y = y, x);

	How are you going to parse this one?  What's the paren supposed
to return?  two assignments or just one?  If one which one?

Dan Kogai (dankg@ocf.berkeley.edu)

wozniak@utkux1.utk.edu (Bryon Lape) (06/29/90)

	Wrong!!  This is an error!!  x would be 1, but y and z would be
unknown.
>	x, y = (x, y = y, x), (x, y = y, x);

	True this is complicated, but not impossible.  Believe it or
not, the concurrent assignment is PDL (expect = is :=) that translates
into PL/I!


-bryon lape-