Previous: , Up: Variable definitions   [Index]


5.3.3 Multiple-value definitions

Another kind of definition is provided by define-values, which creates multiple definitions from a single expression returning multiple values. It is allowed wherever define is allowed.

syntax: define-values ⟨formals⟩ ⟨expression⟩

It is an error if a variable appears more than once in the set of ⟨formals⟩.

Semantics: ⟨Expression⟩ is evaluated, and the ⟨formals⟩ are bound to the return values in the same way that the ⟨formals⟩ in a lambda expression are matched to the arguments in a procedure call.

(define-values (x y) (exact-integer-sqrt 17))
(list x y) ⇒ (4 1)

(let ()
  (define-values (x y) (values 1 2))
  (+ x y)) ⇒ 3