The multiple-value feature was added in R5RS.
call-with-values
thunk
receiver
Call its
thunk
argument with a continuation that, when passed some values, calls thereceiver
procedure with those values as arguments.
let-values
((
formals
expression
)
...
)
body
Each
formals
should be a formal arguments list as for alambda
.The
expression
s are evaluated in the current environment, the variables of theformals
are bound to fresh locations, the return values of theexpression
s are stored in the variables, thebody
is evaluated in the extended environment, and the values of the last expression ofbody
are returned. Thebody
is a "tail body", cf section 3.5 of the R5RS.The matching of each
formals
to values is as for the matching offormals
to arguments in alambda
expression, and it is an error for anexpression
to return a number of values that does not match its correspondingformals
.(let-values (((a b . c) (values 1 2 3 4))) (list a b c)) ⇒ (1 2 (3 4)) (let ((a 'a) (b 'b) (x 'x) (y 'y)) (let-values (((a b) (values x y)) ((x y) (values a b))) (list a b x y))) ⇒ (x y a b)
let*-values
((
formals
expression
)
...
)
body
Each
formals
should be a formal arguments list as for alambda
expression.
let*-values
is similar tolet-values
, but the bindings are performed sequentially from left to right, and the region of a binding indicated by (formals
expression
) is that part of thelet*-values
expression to the right of the binding. Thus the second binding is done in an environment in which the first binding is visible, and so on.(let ((a 'a) (b 'b) (x 'x) (y 'y)) (let*-values (((a b) (values x y)) ((x y) (values a b))) (list a b x y))) ⇒ (x y x y)
receive
formals
expression
body
This convenience form (from SRFI-8) is equivalent to:
(let-values ((formals
expression
))body
)For example:
(receive a (values 1 2 3 4) (reverse a)) ⇒ (4 3 2 1) (receive (a b . c) (values 1 2 3 4) (list a b c)) ⇒ (1 2 (3 4)) (let ((a 'a) (b 'b) (x 'x) (y 'y)) (receive (a b) (values x y) (receive (x y) (values a b) (list a b x y)))) ⇒ (x y x y)