The D Programming Language

Brian Utterback blu at hall.cray.com
Thu Mar 17 06:29:17 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:
>>Here is another feature for D whose absence in C has been irksome to
>>me -- I would like to be able to return several items from a function.
>>... But how do I get stuff back.
>>... Things which are returned need a mechanism equivalent to pass
>>by address.
>
>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?
> Verbal: Dave Burton                        Net: ...!ihnp4!laidbak!daveb

Well, of course that works, but I think the original poster had something else 
in mind.  I think the question was not so much how could you change things
passed to the function, but rather how do we pass more than one thing 
back without changing the original parameters.  He still wanted pass by
value, but with some mechanism for returning several values.  He even 
mentioned having "in", "out" , and "update" parameters, but rejected these as
being unused in current implementations, presumably because users don't
like them.

For instance, you might want to code a function that emulates a Turing Machine.
This function would take a state and an input symbol, and it would return
a new state and an output symbol.  You could pass 4 parameters, 2 by value
for input and 2 by address for the return values, but it would be more natural
to want the function to return the 2 values.  Personally, I prefer having the
extra parameters in the call.  I can see where it would be nice to have
some form of documenting the parametrs like in,out, and update, but that's
more ada than C.  

Boy, you guys should complain.  I used to program APL. We only had 2 input
parameters, and one output.  And I still liked it alot.

Nowadays, you can get APL2 which has multiple input parameters.  Feh.  The
syntax is impenetrable, even for APL.



-- 
Brian Utterback     |UUCP:{ihnp4!cray,sun!tundra}!hall!blu | Think of it as
Cray Research Inc.  |ARPA:blu%hall.cray.com at uc.msc.umn.edu |  evolution in
One Tara Blvd. #301 |                                      |     action
Nashua NH. 03062    |Tele:(603) 888-3083                   |



More information about the Comp.lang.c mailing list