[plt-scheme] PLT v 4.0 discussion - values

From: Mark Engelberg (mark.engelberg at gmail.com)
Date: Thu Jun 5 20:21:50 EDT 2008

Even though "values" have been around a while in Scheme, I've never
really used them.  In most languages, if you want to return multiple
values, you just bundle them up in something like a "tuple" and use a
match-like construct to deconstruct at the receiving end.  This always
worked fine for me, and so I tend to use a similar strategy in Scheme.
 The nice thing about this approach is that if you *want* to delay
destructuring the return values, this is easy to do.  You just pass
them around as a structure until you're ready to use the individual
parts.  Use of "values" seems to impose a higher burden on the caller,
who needs to use special constructs (define/values, let/values, etc.)
to capture and manipulate the multiple values.

I see that in v 4.0, values get a lot more mainstream use (for
example, in comprehension syntax with multiple accumulators), so I
guess I better start getting used to them.  I assume they have
superior performance, which is why they are used in preference to the
structuring/destructing technique.  But I propose values->list and
values->vector macros be included to ease the situation where you
really don't want to bind the values to individual names right away.

Possible implementation:

  (values->list exp)
  (call-with-values (lambda () exp) list))

Example:  (values->list (quotient/remainder 10 3)) evaluates to (list 3 1)

Same for values->vector.


Posted on the users mailing list.