Function: pcase-dolist

pcase-dolist is an autoloaded macro defined in pcase.el.gz.

Signature

(pcase-dolist (PATTERN LIST) BODY...)

Documentation

Eval BODY once for each set of bindings defined by PATTERN and LIST elements.

PATTERN should be a pcase pattern describing the structure of LIST elements, and LIST is a list of objects that match PATTERN, i.e. have a structure that is compatible with PATTERN. For each element of LIST, this macro binds the variables in PATTERN to the corresponding subfields of the LIST element, and then evaluates BODY with these bindings in effect. The destructuring bindings of variables in PATTERN to the subfields of the elements of LIST is performed as if by pcase-let.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/pcase.el.gz
;;;###autoload
(defmacro pcase-dolist (spec &rest body)
  "Eval BODY once for each set of bindings defined by PATTERN and LIST elements.
PATTERN should be a `pcase' pattern describing the structure of
LIST elements, and LIST is a list of objects that match PATTERN,
i.e. have a structure that is compatible with PATTERN.
For each element of LIST, this macro binds the variables in
PATTERN to the corresponding subfields of the LIST element, and
then evaluates BODY with these bindings in effect.  The
destructuring bindings of variables in PATTERN to the subfields
of the elements of LIST is performed as if by `pcase-let'.
\n(fn (PATTERN LIST) BODY...)"
  (declare (indent 1) (debug ((pcase-PAT form) body)))
  (if (pcase--trivial-upat-p (car spec))
      `(dolist ,spec ,@body)
    (let ((tmpvar (gensym "x")))
      `(dolist (,tmpvar ,@(cdr spec))
         (pcase-let* ((,(car spec) ,tmpvar))
           ,@body)))))