Elisp: Foreach (Side-Effect)

By Xah Lee. Date: .

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.)

(setq xx [1 2 3] )
(seq-doseq (x xx)
  (message "x is %s" x))
;; return the original sequence [1 2 3]

Elisp, sequence functions