Re: Multiple return values

danwang@dynamic.CS.Princeton.EDU (Daniel Wang)
20 Apr 1997 12:08:54 -0400

          From comp.compilers

Related articles
[4 earlier articles]
Re: Multiple return values hbaker@netcom.com (1997-04-18)
Re: Multiple return values fjh@mundook.cs.mu.OZ.AU (1997-04-18)
Re: Multiple return values (Mars Saxman) marssaxman%sprynet.com.antispam@nac (marssaxman) (1997-04-18)
Re: Multiple return values preston@tera.com (1997-04-18)
Re: Multiple return values jbuck@Synopsys.COM (1997-04-18)
Re: Multiple return values smryan@mail.com (1997-04-20)
Re: Multiple return values danwang@dynamic.CS.Princeton.EDU (1997-04-20)
Re: Multiple return values smcadams@sprynet.com (steve mcadams) (1997-04-20)
Re: Multiple return values tiggr@es.ele.tue.nl (1997-04-20)
Re: Multiple return values hrubin@stat.purdue.edu (1997-04-20)
Re: Multiple return values fjh@mundook.cs.mu.OZ.AU (1997-04-22)
Re: Multiple return values roy@earthlight.co.nz (1997-04-22)
Re: Multiple return values Robert.Harley@inria.fr (1997-04-22)
[19 later articles]
| List of all articles for this month |

From: danwang@dynamic.CS.Princeton.EDU (Daniel Wang)
Newsgroups: comp.compilers
Date: 20 Apr 1997 12:08:54 -0400
Organization: Princeton University Department of Computer Science
References: 97-04-091 97-04-112
Keywords: syntax, design, functional

(Mars Saxman) marssaxman@sprynet.com> writes:


> I think it is an artefact of the origin of the "function"
> concept.
{stuff deleted}
    It doesn't make sense to have, for example, an arctangent
> return more than one value. Given the origins of computing
> in maths it is easy to see why this habit has been carried
> on.


It makes perfect sense of mathematical functions to return one value which
represents several different values as order pairs/vectors of values. This
is exactly the model that Standard ML use to "simulate" multiple return
values and multiple arguments.


fun vadd((x1,x2),(y1,y2)) = (x1+y1,x2+y2)


...


val (x,y) = vadd((1,2),(1,1))


(* x is bound to 2
y is bound to 3 *)




SML function all take exactly one argument. "vadd" is a function that
takes an ordered pair of ordered pairs and returns an order pair. The
SML/NJ compiler is smart enough to usually optimized all of this into
code that passes and *returns* everything in registers, which it can
do since SML/NJ doesn't follow the standard calling conventions for
the architectures it generates code for. I suspect the lack of
multipule return values is more a function of the lack of standard
assembly level calling conventions that support them.


Someone else pointed out that multiple return values don't buy you
much since you usually can pass variables by reference to simulate
these things. Obviously in functional languages you can't do such a
thing, so you need multipule return values.


Even in languages which you are allowed to do these things you're
making things difficult for you optimizer since now you're passing
arguments that may be aliases of each other. Multipule return values
are semantically different from passing variable by reference and this
difference is important to your optimizer. I wonder if anyone has data
as to how often potential alias in C code arise because of trying to
simulate multiple return values.
--


Post a followup to this message

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