[plt-scheme] Multiple values

From: Robby Findler (robby at cs.uchicago.edu)
Date: Mon Feb 20 16:11:25 EST 2006

At Mon, 20 Feb 2006 13:06:08 -0800, Gregory Woodhouse wrote:
> Looking at the manual, I find it difficult to see how multiple values  
> could be used in a program, except perhaps in conjunction with let- 
> values, as in
> (let-values (((x y) (values 1 2))) (+ x y))
> but I'm not sure whether this is equivalent to
> (let ((x 1) (y 2)) (+ x y))

Those two expressions both produce 3 (in all contexts that don't rebind
things) so they are equivalent in some sense, but the point of multiple
values is, I believe, so that a function can compute two results
simultaneously and then return those two results together (without
having to create a pair). So, if you were to think of this slightly
more generally, you might compare this:

  (let ([x (compute-x ...)]
        [y (compute-y ...)])
    (+ x y))

to this:

  (let-values ([(x y) (compute-both-x-and-y ...)])
    (+ x y))


Posted on the users mailing list.