Article View: comp.arch
Article #1626Re: Language Tenets (was Re: Double Width Integer Multiplication and Division
From: Dan Weinreb
Date: Fri, 21 Jul 1989 23:36
Date: Fri, 21 Jul 1989 23:36
50 lines
2908 bytes
2908 bytes
From: gateley@m2.csc.ti.com (John Gateley)
Newsgroups: comp.arch,comp.lang.misc
In the divrem example being discussed for example, many of the problems
center around using the quotient and remainder after they have been
returned. But the only things it makes sense to do with them is either
return them as values to someone else, or unpackage them and use them.
After unpackaging them, they are no longer multiple values, and should
not be thought of as such.
I don't know what you mean by unpackaging them. The typical use I'd
make of a divrem function, in the high-level terms in which I think,
is usually something like this:
(1) compute the numerator
(2) compute the denominator
(3) perform divrem
(4) give a name to the quotient and remainder
(5) proceed with my computation, now that I have the quotient and remainder
For example,
(multiple-value-bind (n-blocks offset-within-block)
(divrem (get-total-size-in-units) size-of-block-in-units)
(format t "There are %d blocks, with %d units left over%n"
n-blocks offset-within-block)
(dotimes (i n-blocks)
(process-one-block))
... and so on ...
)
Back before we had multiple values, we had to create bogus structures;
divrem would return one, then we'd need this awkward code to extract
the values from the structure. To add insult to injury, the structure
was then garbage and contributed eventually to GC costs. The great
thing about this style is that there isn't any unpackaging. There
isn't any synthetic, bogus, distracting object whose only purpose is
to hold the two values.
Such an object is bogus because it does not model any concept at the
level of the application; it's only there for programming language
purposes, not because it is a useful expression of what the program is
about. (Usually, you notice this when you try to figure out what its
name is. Usually there isn't any good name and you have to make up
something rather non-mnemonic and awkward.)
I used the programming style illustrated above in Zetalisp and Common
Lisp for about ten years, and in my experience and opinion, it's quite
useful and readable.
Technical Details
Message-ID:
<395@odi.ODI.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!odi!valens!dlwReferences:
<57125@linus.UUCP> <1989Jun24.230056.27774@utzoo.uucp> <13946@haddock.ima.isc.com> <1388@l.cc.purdue.edu> <13961@haddock.ima.isc.com> <147@ssp1.idca.tds.philips.nl> <1207@quintus.UUCP> <84306@ti-csl.csc.ti.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!odi!valens!dlw From: dlw@odi.com (Dan Weinreb) Newsgroups: comp.arch Subject: Re: Language Tenets (was Re: Double Width Integer Multiplication and Division Message-ID: <395@odi.ODI.COM> Date: 21 Jul 89 23:36:58 GMT References: <57125@linus.UUCP> <1989Jun24.230056.27774@utzoo.uucp> <13946@haddock.ima.isc.com> <1388@l.cc.purdue.edu> <13961@haddock.ima.isc.com> <147@ssp1.idca.tds.philips.nl> <1207@quintus.UUCP> <84306@ti-csl.csc.ti.com> Sender: news@odi.com Reply-To: dlw@odi.com Followup-To: comp.arch Lines: 50 In-reply-to: gateley@m2.csc.ti.com's message of 16 Jul 89 02:45:24 GMT