Skip to main content

multiple-value-list

multiple-value-list Macro

Syntax:

multiple-value-list form ! list

Arguments and Values:

form—a form; evaluated as described below.

list—a list of the values returned by form.

Data and Control

Description:

multiple-value-list evaluates form and creates a list of the multiple values2 it returns.

Examples:

(multiple-value-list (floor -3 4)) *!* (-1 1) 

See Also:

values-list, multiple-value-call

Notes:

multiple-value-list and values-list are inverses of each other.

(multiple-value-list form) (multiple-value-call #’list form)

Expanded Reference: multiple-value-list

Capturing multiple values as a list

multiple-value-list evaluates a form and collects all of its return values into a list.

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

(multiple-value-list (values))
=> NIL

Capturing values from floor and truncate

This is especially useful with functions that return multiple values, like floor, truncate, and gethash.

(multiple-value-list (floor 7 3))
=> (2 1)

(multiple-value-list (truncate 3.7))
=> (3 0.70000005)

Inspecting what a function returns

multiple-value-list is a handy debugging tool to see all the values a form produces.

(multiple-value-list (gethash 'missing (make-hash-table)))
=> (NIL NIL)

(multiple-value-list (parse-integer "123abc" :junk-allowed t))
=> (123 3)

Single-value forms produce a one-element list

When the form returns only one value, the result is a single-element list.

(multiple-value-list (+ 1 2))
=> (3)

(multiple-value-list 'hello)
=> (HELLO)

Inverse of values-list

multiple-value-list and values-list are inverses of each other.

(values-list (multiple-value-list (floor 10 3)))
=> 3
=> 1

(multiple-value-list (values-list '(a b c)))
=> (A B C)