[plt-scheme] Why multiple values?

From: gregory.woodhouse at sbcglobal.net (gregory.woodhouse at sbcglobal.net)
Date: Sun Dec 24 18:23:56 EST 2006

That makes sense. I don't feel entirely t eade with pattern matching in languages like ML and Haskell, either, but I can see how let-values would do something similar for Scheme (without the _, that is). 

So, here's another basic question: If I know that f returns multiple values, but I don't know how many, but I do know that I only care about, say, the first two values, can I get them as x and y? Can I gain access to all the values, even if I don't know in advance how many there are?
 
===
Gregory Woodhouse 
 
"Mathematics is the science of patterns."
--Lynn Arthur Steen, 1988


----- Original Message ----
From: Carl Eastlund <cce at ccs.neu.edu>
To: Corey Sweeney <corey.sweeney at gmail.com>
Cc: "gregory.woodhouse at sbcglobal.net" <gregory.woodhouse at sbcglobal.net>; PLT Scheme <plt-scheme at list.cs.brown.edu>
Sent: Sunday, December 24, 2006 2:25:21 PM
Subject: Re: [plt-scheme] Why multiple values?


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.  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".

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


Posted on the users mailing list.