Subject: Re: purpose of call-with-values
From: (Rob Warnock)
Date: Sat, 10 Apr 2004 06:08:46 -0500
Newsgroups: comp.lang.scheme
Message-ID: <>
Kristof Bastiaensen  <> wrote:
| I am wondering about the purpose of call-with-values. I looks to me
| like a totally unnecessary construct. If you want to return multiple
| values, can't you just return a list?
| call-with-values doesn't really add something to the language, or
| am I missing something?

The latter.

Yes, it it true that an implementation could do this (and remain *almost*
conforming with R5RS):

	(define values list)
	(define (call-with-values producer consumer)
	  (apply consumer (producer)))

but having a real VALUES/CALL-WITH-VALUES allows a "sufficiently smart
compiler" (SSC) to avoid consing up a list for the values and instead
allow PRODUCER to return them in registers where CONSUMER expects them
to be. This is particularly important when you wrap convenience macros
around CALL-WITH-VALUES to do result destructuring, e.g., such as
MzScheme's LET-VALUES:

	(let-values (((a b c) producer))
	  ...a body
	    that uses
	      A, B, and C...

An SSC can simply bind A, B, & C to the registers that PRODUCER returned
them in: "Look Ma, no consing!"


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607