chickadee » scheme » base » let-values

(let-values <mv binding spec> <body>)syntax

Syntax: <Mv binding spec> has the form ((<formals[1]> <init[1]>) ...), where each <init> is an expression, and <body> is zero or more definitions followed by a sequence of one or more expressions as described in section 4.1.4. It is an error for a variable to appear more than once in the set of <formals>.

Semantics: The <init>s are evaluated in the current environment (in some unspecified order) as if by invoking call-with-values, and the variables occurring in the <formals> are bound to fresh locations holding the values returned by the <init>s, where the <formals> are matched to the return values in the same way that the <formals> in a lambda expression are matched to the arguments in a procedure call. Then, the <body> is evaluated in the extended environment, and the values of the last expression of <body> are returned. Each binding of a <variable> has <body> as its region.

It is an error if the <formals> do not match the number of values returned by the corresponding <init>.

{{ (let-values (((root rem) (exact-integer-sqrt 32)))

 (* root rem))                 ==>  35

}}