values-list
values-list Function
Syntax:
values-list list ! {element}*
Arguments and Values:
list—a list.
elements—the elements of the list.
Description:
Returns the elements of the list as multiple values2.
Examples:
(values-list nil) *! ⟨no values⟩*
(values-list ’(1)) *!* 1
(values-list ’(1 2)) *!* 1, 2
(values-list ’(1 2 3)) *!* 1, 2, 3
Exceptional Situations:
Should signal type-error if its argument is not a proper list.
See Also:
multiple-value-bind, multiple-value-list, multiple-values-limit, values
Notes:
(values-list list) ⌘ (apply #’values list)
(equal x (multiple-value-list (values-list x))) returns true for all lists x.
Data and Control
Expanded Reference: values-list
Converting a list to multiple values
values-list returns the elements of a list as multiple values. It is equivalent to (apply #'values list).
(values-list '(1 2 3))
=> 1
=> 2
=> 3
Empty list returns no values
(values-list '())
;; => (no values returned)
Single-element list returns one value
(values-list '(42))
=> 42
Using with multiple-value-bind
values-list is useful when you have a list of values that you want to bind to separate variables.
(multiple-value-bind (x y z)
(values-list '(10 20 30))
(+ x y z))
=> 60
Round-tripping with multiple-value-list
values-list and multiple-value-list are inverses of each other.
(multiple-value-list (values-list '(a b c)))
=> (A B C)
(values-list (multiple-value-list (floor 17 5)))
=> 3
=> 2