Previous: Loop Facility, Up: Control Structure

4.8 Multiple Values

Common Lisp functions can return zero or more results. Emacs Lisp functions, by contrast, always return exactly one result. This package makes no attempt to emulate Common Lisp multiple return values; Emacs versions of Common Lisp functions that return more than one value either return just the first value (as in cl-compiler-macroexpand) or return a list of values. This package does define placeholders for the Common Lisp functions that work with multiple values, but in Emacs Lisp these functions simply operate on lists instead. The cl-values form, for example, is a synonym for list in Emacs.

— Macro: cl-multiple-value-bind (var...) values-form forms...

This form evaluates values-form, which must return a list of values. It then binds the vars to these respective values, as if by let, and then executes the body forms. If there are more vars than values, the extra vars are bound to nil. If there are fewer vars than values, the excess values are ignored.

— Macro: cl-multiple-value-setq (var...) form

This form evaluates form, which must return a list of values. It then sets the vars to these respective values, as if by setq. Extra vars or values are treated the same as in cl-multiple-value-bind.

Since a perfect emulation is not feasible in Emacs Lisp, this package opts to keep it as simple and predictable as possible.