[plt-scheme] Multiple values

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Feb 21 01:03:21 EST 2006

At Mon, 20 Feb 2006 22:21:34 -0700, Richard Cleis wrote:
> > As yet no-one has commented on my original question, which is how
> > compelling is the argument for a multiple-values facility in Scheme?
> This is the answer I am waiting for; I've been tossing in solutions 
> that don't require multiple-values, hoping that someone will hammer me 
> with a killer counter example.  I use multiple-values with functions 
> like udp-receive! because that's what is provided, but I don't see why 
> it's any better than a list of '(n ip port).  I barely remember 
> generating multiple-values during some state-vector processing a while 
> back, but I can't recall if they provided a better solution than lists 
> would have anyway.

I don't really consider myself a proponent of multiple values, but I
think the official argument is that they don't require you to allocate.

Also, it my taste that a list should represent things where the number
of elements varies. That is, I like to try to use cons and null when my
function consumes/produces arbitrary values of this shape (in HtDP

  a list-of-X is either
   - null
   - (cons X list-of-X)

instead of values where you know how many pairs there are going to be,
always. In those cases, I find a struct works better (or, were I
programming in ML, a tuple). 

This is partly just a matter of taste, but using different kinds of
records for fixed-size objects also makes it easier to write more
effective contracts (and types). That is, I won't accidentally switch
the order of the arguments to some function somewhere and accidentally
pass list like the above with the `length' function and then carry
merrily (when I could have gotten an error that would have probably led
me to the switched order-of-args call).


Posted on the users mailing list.