🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #5406

Re: multiple values

#5406
From: Barry Margolin
Date: Wed, 30 Mar 1988 03:46
43 lines
2490 bytes
In article <3213@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes:
>So?  The way I wrote it, q and r are never more than unnamed virtual objects.
>I'm looking for a syntax that allows all three (qr, q, r) to disappear, if
>all I really want is an expression that returns q*q+r*r.  If we allow 2-d
>notation, this could be written

I thought we were discussing multiple-valued functions, not language
syntax.  I would expect each language to use a syntax for multiple
values that is consistent with the rest of the language.  In Lisp, if
you want to use something twice, you must name it with a variable;
Forth, on the other hand, lets you (requires you to?) manipulate the
stack directly.  These features are independent of whether functions
can return multiple values.

So, if Lisp requires me to say

(multiple-value-bind (q r) (floor x y)
  (+ (* q q) (* r r)))

that is because this is a Lispy way to do it.  If you don't like Lisp,
fine, but don't put down its multiple-value feature because it is
consistent with the rest of the language.

By the way, when you don't want to refer to a value twice, but just
want to pass it along to another function, you can do that:

(multiple-value-call #'+ (floor x y))

adds the quotient and remainder, which are, indeed, unnamed virtual
objects.  Unfortunately, there's no built-in swap operation as there
is in Forth, so if the function being called takes its arguments in a
different order from the return values you must bind variables to
them.  There's no fundamental reason why Common Lisp couldn't have
such an operation (although I'm not sure what it would mean when the
function doesn't return exactly two values), it just wasn't considered
necessary when the language was being designed, presumably because
variable binding is a much more familiar concept to Lisp programmers.

Barry Margolin
Thinking Machines Corp.

barmar@think.com
uunet!think!barmar
Technical Details
Message-ID: <18644@think.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bbn!mit-eddie!bloom-beacon!think!barmar
References: <12176@brl-adm.ARPA> <1988Mar11.215238.976@utzoo.uucp> <3177@haddock.ISC.COM> <727@l.cc.purdue.edu> <3213@haddock.ISC.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bbn!mit-eddie!bloom-beacon!think!barmar
From: barmar@think.COM (Barry Margolin)
Newsgroups: comp.lang.misc
Subject: Re: multiple values
Message-ID: <18644@think.UUCP>
Date: 30 Mar 88 03:46:44 GMT
References: <12176@brl-adm.ARPA> <1988Mar11.215238.976@utzoo.uucp> <3177@haddock.ISC.COM> <727@l.cc.purdue.edu> <3213@haddock.ISC.COM>
Sender: usenet@think.UUCP
Reply-To: barmar@fafnir.think.com.UUCP (Barry Margolin)
Organization: Thinking Machines Corporation, Cambridge, MA
Lines: 43