Function: cl-multiple-value-bind

cl-multiple-value-bind is an autoloaded macro defined in cl-macs.el.gz.

Signature

(cl-multiple-value-bind (SYM...) FORM BODY)

Documentation

Collect multiple return values.

FORM must return a list; the BODY is then executed with the first N elements of this list bound (let-style) to each of the symbols SYM in turn. This is analogous to the Common Lisp multiple-value-bind macro, using lists to simulate true multiple return values. For compatibility, (cl-values A B C) is a synonym for (list A B C).

Aliases

multiple-value-bind (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-macs.el.gz
;;; Multiple values.

;;;###autoload
(defmacro cl-multiple-value-bind (vars form &rest body)
  "Collect multiple return values.
FORM must return a list; the BODY is then executed with the first N elements
of this list bound (`let'-style) to each of the symbols SYM in turn.  This
is analogous to the Common Lisp `multiple-value-bind' macro, using lists to
simulate true multiple return values.  For compatibility, (cl-values A B C) is
a synonym for (list A B C).

\(fn (SYM...) FORM BODY)"
  (declare (indent 2) (debug ((&rest symbolp) form body)))
  (let ((temp (make-symbol "--cl-var--")) (n -1))
    `(let* ((,temp ,form)
            ,@(mapcar (lambda (v)
                        (list v `(nth ,(setq n (1+ n)) ,temp)))
                      vars))
       ,@body)))