Function: dolist

dolist is a macro defined in subr.el.gz.

Signature

(dolist (VAR LIST [RESULT]) BODY...)

Documentation

Loop over a list.

Evaluate BODY with VAR bound to each car from LIST, in turn. Then evaluate RESULT to get return value, default nil.

This macro has :around advice: cl--wrap-in-nil-block.

View in manual

Probably introduced at or before Emacs version 21.1.

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defmacro dolist (spec &rest body)
  "Loop over a list.
Evaluate BODY with VAR bound to each car from LIST, in turn.
Then evaluate RESULT to get return value, default nil.

\(fn (VAR LIST [RESULT]) BODY...)"
  (declare (indent 1) (debug ((symbolp form &optional form) body)))
  (unless (consp spec)
    (signal 'wrong-type-argument (list 'consp spec)))
  (unless (<= 2 (length spec) 3)
    (signal 'wrong-number-of-arguments (list '(2 . 3) (length spec))))
  (let ((tail (make-symbol "tail")))
    `(let ((,tail ,(nth 1 spec)))
       (while ,tail
         (let ((,(car spec) (car ,tail)))
           ,@body
           (setq ,tail (cdr ,tail))))
       ,@(cdr (cdr spec)))))