[plt-scheme] Why multiple values?

From: Corey Sweeney (corey.sweeney at gmail.com)
Date: Mon Dec 25 13:37:08 EST 2006

On 12/24/06, Carl Eastlund <cce at ccs.neu.edu> wrote:
> On 12/24/06, Corey Sweeney <corey.sweeney at gmail.com> wrote:
> >
> > And the rest prefer not to construct an arbitrary, irrelevant syntax so
> they
> > use lists ;)
> >
> > But I do see your point.  I can now see why some people are using
> > multi-value's.  But I would argue that it should be a compiler thing,
> not a
> > syntax thing.
> Scheme has multiple inputs without resorting to lists (for functions
> of fixed input size), so having the same thing for outputs isn't
> really arbitrary or irrelevant.

heh.  Multiple inputs is generally a arbitrary syntax too.  I basically see
"(define (my-function a b c) {blah}))" as syntactic sugar for:

"(define my-function (lambda (a) (lambda (b) (labmda (c) {blah}))))"

Your function "{blah}" works the same either way.  Also "(my-function x y
z)" would be syntacitic sugar for "(((my-function x) y) z)".
The only differnce from the users perspective is that when implemented as
"multi input values syntax" instead of a "bunch of lambdas syntax", then the
interpreter can check for arity errors when calling.  I.E.  in the "bunch of
lambdas syntax" method, (define add-two (+ 2)) becomes a valid function, but
in the multi input values syntax method (define add-two (+ 2)) throws a
arity error and says that it can't work without 2 parameters, so you need to
do:  (define add-two (lambda (x) (+ 2 x))).

However I usually use the "multi value syntax", because in normal R5RS
intrepeters, "(my-function x y z)" is not syntacitic sugar for
"(((my-function x) y) z)".

in the "bunch of lambda functions syntax" any result list of length 3 or
less can be "folded" into my-function.  in "multi input values syntax" you
get arity errors.

 Lists (linear, arbitrary-size,
> usually homogenous data structures), on the other hand, are not a
> close fit (for flat, fixed-size, often heterogenous function outputs).
> Anyway, this isn't (just) an efficiency issue.  It's a matter of what
> the programmer can express.  Multiple values says "this program
> outputs these two things".  Lists say "this program outputs a list".

I think were settled on the effiency issue, but I'm not seeing the
non-effencity issue in this one.  Are you saying that when i have a set of
numbers, that i'm actually saying "i have a set of numbers, not a list of
numbers with special set properties added to them"?  I.E. like we should add
set as a new primative because I want to name it differntly then "list of
numbers with special set properties"?  If we've discarded effencicy issues,
then we shouldn't need such a thing, right?


Multiple values aren't my favorite program construct either, but I
> think we've covered the ground of why they exist as they are.
> --
> Carl Eastlund

((lambda (y) (y y)) (lambda (y) (y y)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20061225/35c12bff/attachment.html>

Posted on the users mailing list.