Common Lisp Extensions. Node: Multiple Values

PREV Loop Facility UP Control Structure next

5.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 compiler-macroexpand) or return a list of values (as in get-setf-method). 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 values form, for example, is a synonym for list in Emacs.

Special Form: 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.
Special Form: 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 multiple-value-bind.

The older Quiroz package attempted a more faithful (but still imperfect) emulation of Common Lisp multiple values. The old method ``usually'' simulated true multiple values quite well, but under certain circumstances would leave spurious return values in memory where a later, unrelated multiple-value-bind form would see them.

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

PREV Loop Facility UP Control Structure next