Elisp: Sequence. Foreach

By Xah Lee. Date: . Last updated: .

Foreach (Side-Effect, Do Not Care Result)

mapc

(mapc FUNCTION SEQUENCE)

  • Apply function to each element of Sequence
  • Return SEQUENCE unchanged.
(mapc
 (lambda (x)
   (insert (number-to-string x)))
 (number-sequence 1 9))

;; insert 123456789
;; apply a file function to a list of files
(mapc 'my-update-footer
      (list "~/x1.html" "~/x2.html" "~/x3.html"))
seq-do (alias seq-each)

Loop a function over the sequence. (similar to mapc)

seq-doseq

(seq-doseq (VAR SEQUENCE) BODY)

loop a variable over the sequence. (similar to dolist.)

(seq-doseq (x [1 2 3])
  (message "x is %s" x))

;; x is 1
;; x is 2
;; x is 3

;; return
;; [1 2 3]

Elisp, sequence functions