Re: Multiple return values (Fergus Henderson)
22 Apr 1997 21:05:27 -0400

          From comp.compilers

Related articles
[8 earlier articles]
Re: Multiple return values jbuck@Synopsys.COM (1997-04-18)
Re: Multiple return values (1997-04-20)
Re: Multiple return values danwang@dynamic.CS.Princeton.EDU (1997-04-20)
Re: Multiple return values (steve mcadams) (1997-04-20)
Re: Multiple return values (1997-04-20)
Re: Multiple return values (1997-04-20)
Re: Multiple return values (1997-04-22)
Re: Multiple return values (1997-04-22)
Re: Multiple return values (1997-04-22)
Re: Multiple return values (Mike Ashley) (1997-04-22)
Re: Multiple return values (Craig Burley) (1997-04-22)
Re: Multiple return values (1997-04-22)
Re: Multiple return values (1997-04-30)
[15 later articles]
| List of all articles for this month |

From: (Fergus Henderson)
Newsgroups: comp.compilers,comp.lang.misc
Date: 22 Apr 1997 21:05:27 -0400
Organization: Comp Sci, University of Melbourne
References: 97-04-091 97-04-109 97-04-128
Keywords: design

>[Fergus Henderson wrote:]
>> Many if not most programming languages allow procedures with
>> multiple output arguments. For example, instead of
>> (x, y) = foo(a, b);
>> in C you can write
>> foo(a, b, &x, &y); (!@?*$%) writes:
>These are semantically distinct. The second requires additional notions
>such as variables, addresses, assignments, nonlocal side effects,
>aliassing, etc.

Well, what do you want -- do you want multiple return values for
efficiency, or for syntactic convenience, or both?

The issues you raise are mostly issues for C, because C doesn't really
have output mode arguments (you have to use pointers to simulate
them). These issues don't cause problems in languages such as Ada,
Sather, and Mercury. Using output mode arguments in these languages
give you both efficiency (the compiler can easily return multiple
results in registers) and syntactic convenience.

Herman Rubin complained about the "attrocious prenex syntax" of output
mode arguments, and while I think "attrocious" is a too strong, and I
don't think that there is necessarily anything wrong with using prefix
notation for this sort of thing, he does have a point: it certainly
helps if you can easily tell which arguments are input and which are
output. In the development environment I use, the mode declarations
are only a single keystroke away, but there is certainly an argument
for putting annotations for output arguments on the call, not just on
the procedure declaration.

The SML approach of providing nice syntax for functions that return
tuples can work too, but it requires a more sophisticated compiler to
make it efficient. Using a different calling convention for such
functions is not too difficult, but in a language with support for
Hindley/Milner style polymorphism like SML, the compiler needs to do a
bit of fancy footwork when you take the address of such a function.

I suppose the approach that Pieter Schoenmakers described is a
compromise; in his language "Tom", tuples are not first-class types,
and so it would probably be easy for a compiler to return tuples of
results in registers. But I think I'd prefer tuples to be first-class

Fergus Henderson <>
WWW: <>
PGP: finger fjh@

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.