Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.ecn.bgu.edu!usenet.ins.cwru.edu!howland.reston.ans.net!news.sprintlink.net!siemens!princeton!news.princeton.edu!blume
From: blume@dynamic.cs.princeton.edu (Matthias Blume)
Subject: Re: Explanation about call-with-values
In-Reply-To: Ken Dickey's message of 17 Jan 1995 19:14:45 GMT
Message-ID: <BLUME.95Jan18102804@dynamic.cs.princeton.edu>
Originator: news@hedgehog.Princeton.EDU
Sender: news@Princeton.EDU (USENET News System)
Nntp-Posting-Host: dynamic.cs.princeton.edu
Organization: Princeton University
References: <BRENT.BENSON.95Jan4201445@jade.ssd.csd.harris.com>
	<3ejq4q$cva@agate.berkeley.edu> <3fh4v5$aup@apple.com>
Date: Wed, 18 Jan 1995 15:28:04 GMT
Lines: 64

In article <3fh4v5$aup@apple.com> Ken Dickey <kend@newton.apple.com> writes:

   > From: bh@anarres.CS.Berkeley.EDU (Brian Harvey)
   > I think what he really wants explained is why using a list
   of values
   > wouldn't be just as good.  Someone else posted saying that
   multiple
   > values can be implemented more efficiently, e.g., as a
   vector -- but
   > that still leaves us with the question of why a vector of
   values
   > wouldn't be just as good!

   The point is that with call-with-values, the compiler can
   simply transfer 
   values directly (e.g. stuff the registers) rather than
   creating *any* 
   data structure.  Less memory traffic => better performance. 

This seems like a pretty pointless minor optimization, which doesn't
justify the introduction of a new language element.  ``Programming
languages should be designed not by...''  -- Rings a bell?

Given that Scheme's current design makes it pretty hard to optimize
even (usually) trivial things for speed (such as arithmetic because of
the very general number type tower) this kind of optimization is
hardly worth the paper it is proposed on.  Has anybody measured the
benefits from using call-with-values?

On top of that, the use of call-with-values is so awkward, that it
wouldn't be much more complicated to do things by hand:  simply pass
an explicit multi-argument continuation procedure and call it instead
of returning some `(values ...)'!

   The use of 
   call-with-values enables comparatively simple compiler
   analysis.

I seriously doubt that, given the fact that it is possible to pass
both `values' and `call-with-values' as arguments to higher-order
functions.  The compiler must be prepared for the call to `f' (or `h'
for that matter) in

	(define (g f h x)
	  (f (h x)))

really being a call to `values'.  This can't be determined at compile
time (at least not in general).

I go with Brian here: an explicitly constructed vector (or cons cell)
of values does the job nearly as well as `values'.  And if it really
becomes a bottleneck (but *only* then!) then convert it to CPS!  In
addition, I would venture to say that in places where the compiler can
benefit from `values' and `call-with-values' it wouldn't be too hard
to find corresponding `vector' and `vector-ref' calls (and to optimize
them away) either.

[As an aside:  even if the compiler sees an explicitly written down
`call-with-values' -- how does it know that nobody re-defines this
identifier later on?   Back to the old module-system debate... :)]

Regards,
--
-Matthias
