πŸ“Common Lisp: multiple values

Use value or values-list to construct multiple values for return. values accepts multiples arguments, and values-list accepts a single list. i.e.,

(values-list x) === (apply #'values x)

Use multiple-value-bind to read the result.

(multiple-value-bind (x y z) (f a b)
  ...)

multiple-value-list converts multiple values into a list:

(multiple-value-list (values 1 2)) ;=> (1 2)

values is also setfβ€˜able:

(setf (values *x* *y*) (floor (/ 57 34)))
*x* ;=> 1
*y* ;=> 23/34

Multiple values works via special operator multiple-value-call primitive which calls a specified function passing in all values:

(funcall #'+ (values 1 2) (values 3 4))             ; => 4
(multiple-value-call #'+ (values 1 2) (values 3 4)) ; => 10

Backlinks