[comp.theory] Why not multiple out parameters?

tmb@ai.mit.edu (Thomas M. Breuel) (09/12/90)

The problem of how to return multiple values has solved very
elegantly in many languages through the use of anonymous
compound data structures together with destructuring binding
and assignment. These techniques have actually been around
for quite some time.

In languages like ML, you can therefore quite naturally write:

	fun cossin x = (cos x,sin x)
	val (c,s) = cossin 1.1

In Lisp, this method for returning multiple values and using
them has been in use for a long time. Unfortunately, the
CommonLisp language designers were a little squeamish about
efficiency and added a redundant VALUES construct and its
associated hair to the language.

In article <3788@osc.COM>, jgk@osc.COM (Joe Keane) writes:
|> I think returning a record just gets around the issue.  
|> We don't use a single record to pass all the in parameters 
|> to a function, so why should we do it for
|> out parameters?

But "we" would like to. Again, in ML, you can write:

	fun f(x,y) = x+y
	val args = (3,4)
	val result = f args
	val result' = f(args)   (* identical to "f args" *)

In essence, functions in ML really only take one value as an
argument and return one value as a result, but because it
is so easy to build and destructure compound data structures
as you go along, the effect is that you get multiple arguments
and multiple return values very naturally and simply. In fact,
it also gives you keyword arguments and the equivalent of
ALLOW-OTHER-KEYS for free.

After seeing how nicely and consistently these things work in
languages like ML, other conventions, even those in Lisp, seem
rather messy, unnecessarily complicated, and weird.