The D Programming Language

Bob Rose rrr at naucse.UUCP
Wed Mar 9 06:51:31 AEST 1988


In article <1354 at laidbak.UUCP>, daveb at laidbak.UUCP (Dave Burton) writes:
> In article <25284 at cca.CCA.COM> g-rh at CCA.CCA.COM.UUCP (Richard Harter) writes:
> >I would like to be able to return several items from a function.
> Please don't design D until you understand C.
> C has had pass by reference for a very long time (since its inception?).
> The following useless code illustrates:
> 
> 	int flag, foobar();
> 	x = foobar(&flag);
> 	...
> 	int foobar(arg)	int *arg;
> 	{*arg = 1;return 0;}
> 
> Now, what could be simpler?
Easy

	[int, int] foobar()		/* prototype */

	....
	[x, flag] = foobar();
	....

	[int, int] foobar()
	{
		return [0, 1];
	}

Yes I admit this looks a bit strange but look at some of the things
we can do with multi assignments

	[x, y] = [y, x]		/* swap */

The only question is should we be allowed to index this stuff so

	if (([x, flag] = foobar())[1]) {
		/* the flag was true */
		....
	}

Anyone for comp.lang.d

Robert R. Rose
Northern Arizona University, Box 15600
Flagstaff, AZ 86011
                    .....!ihnp4!arizona!naucse!rrr



More information about the Comp.lang.c mailing list