[plt-scheme] match multiple values

From: Robby Findler (robby at cs.uchicago.edu)
Date: Fri May 4 12:19:07 EDT 2007

On 5/4/07, Robert Nikander <nikander at nc.rr.com> wrote:
> Hi all,
> Is there a way to use match, match-let, etc, with (values v ...).
> Something like this:
> (match (values 1 2)
>   ((a b) b))
> => 2

Only something like

  (match (call-with-values f list)
    [(a b) b])

where f is

  (define (f) (values 1 2))

or whatever.

> Related question: since we have the ML-style binding forms in "match.ss"
> and "plt-match.ss", is there a reason to prefer returning (values v ...)
> from a function, as opposed to a list or vector or something else?  It
> looks to me like the "values" form was invented to have a way to return
> multiple values without making the caller explicitly take apart a list.
> The match forms seems so much better at that, but many standard
> functions return (values v ...).

lists require allocation, but values don't. That's why the standard
libraries avoid lists (not to mention lists connote an arbitrary
number of values, so it is a little bit bad style to return a fixed
length list. Of course, some prims still do this).


Posted on the users mailing list.