A form typically returns only one value. Lisp has only a small number of forms which create or receive multiple values.
VALUES form creates zero or more values:
(values :this :that)
We show how many values are returned by the number of lines produced
by the evaluation of the form. The three
VALUES forms in the
example above produced zero, one, and two values, respectively.
VALUES is a function, and so evaluates its arguments.
What might you want to do with multiple values in a program? The most basic operations are to:
MULTIPLE-VALUE-BIND to bind each value to a separate
(multiple-value-bind (a b c) (values 2 3 5)
(+ a b c))
If you provide more values than symbols, the excess values are ignored:
(multiple-value-bind (a b c) (values 2 3 5 'x 'y)
(+ a b c))
If you provide fewer values than symbols, the excess symbols are bound
(multiple-value-bind (w x y z) (values :left :right)
(list w x y z))
(:LEFT :RIGHT NIL NIL)
Some forms pass along the last value in their body, rather than
creating a new value. Examples include the bodies of
(let ((a 1)
(values a b))
(cond (nil 97)
(t (values 3 4)))
(defun foo (p q)
(values (list :p p) (list :q q)))
(foo 5 6)
((lambda (r s)
(values r s))
In the case of the function and lambda bodies, the multiple values are actually returned by something called an "implicit
PROGN." This is a fancy way of saying that the bodies can contain multiple forms, and only the value of the last form is returned.
You can use the
PROGNspecial form when you want this behavior.
(PROGN form1 form2 ... formN)evaluates
formNin order, and returns the value of