[net.lang.c] How About Agregate Formation and Return?

mat@hou5d.UUCP (11/04/83)

Well, we keep talking about blue-sky additions to C.  I have two favorites
of my own.  They are structure aggregation and disaggregation.

	struct x
	{
		int	depth;
		int	bucket;
		char	*tag;
		struct x	*brother;
	};

	struct x x_obj, x_funct();

	...


	/*
	 * Agreggation
	 */

	x_obj = {	depth: 2,	bucket: alpha,
			tag: x_obj2.tag,	brother: &x_obj2
		};

	/*
	 * Disaggregation
	 */
	{	depth: d,	bucket: buck,
		tag: ; /* discard */ brother: ; /* ditto */
	} = x_funct();

I cannot take credit for the idea of disaggregation.  I first saw it in SETL,
which is a set-symbology language for rapid prototyping developed by Jack
Schwartz of NYU/Courant.


						Mark Terribile
						hou5d!mat

leichter@yale-com.UUCP (Jerry Leichter) (11/04/83)

The biggest use of this kind of aggregate synthesis/analysis is in Mesa.  in
fact, in Mesa, if f is declared to take an integer argument followed by a
real, the semantic effect is really to say that it takes an (unnamed) structure
of two fields, the first integer, the second real, as an argument.  Because
of the way defaults and conversions work, f(1,2.0) works as you expect, but
you can also (sometimes? - I don't remember the details) do f(x) where x is
a variable whose type is a structure of two fields, etc.  The "return" case is
completely symmetrical.  What makes this all work is that you can build
structures on the fly:  [1,2.0] is a structure of the appropriate type, as is
[i,y] where i and y are integer and real; [i,y] = f(...) is how you would
write an assignment when f returns [1,2.0].

							-- Jerry
					decvax!yale-comix!leichter leichter@yale