[plt-scheme] Why multiple values?

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Sun Dec 24 14:14:48 EST 2006

On 12/24/06, Greg Woodhouse <gregory.woodhouse at sbcglobal.net> wrote:
> This is undoubtedly a basic question, but I don't think I quite grasp the concept behind (values ...). I know I can write, say
> (define-values (x y z) (values 1 2 3))
> but I don't understand why this construct is needed. Couldn't I just as easily write
> (define x 1)
> (define y 2)
> (define z 3) ?
> I kind of suspect values is there because it supports some programming idiom, or because it is needed in conjunction with some other language feature, but I'm not sure what.

Yes, but if you call a function that produces two values, breaking it
up into two functions that each produce one value might require
duplicating computation.  Multiple values helps when the values come
from a single source that can't be split up.

Carl Eastlund

Posted on the users mailing list.