Function: --each-r

--each-r is a macro defined in dash.el.

Signature

(--each-r LIST &rest BODY)

Documentation

Evaluate BODY for each element of LIST in reversed order.

Each element of LIST in turn, starting at its end, is bound to it and its index within LIST to it-index before evaluating BODY. The return value is always nil. This is the anaphoric counterpart to -each-r.

Source Code

;; Defined in ~/.emacs.d/elpa/dash-20260221.1346/dash.el
(defmacro --each-r (list &rest body)
  "Evaluate BODY for each element of LIST in reversed order.
Each element of LIST in turn, starting at its end, is bound to
`it' and its index within LIST to `it-index' before evaluating
BODY.  The return value is always nil.
This is the anaphoric counterpart to `-each-r'."
  (declare (debug (form body)) (indent 1))
  (let ((v (make-symbol "vector"))
        (i (make-symbol "i")))
    ;; Implementation note: building a vector is considerably faster
    ;; than building a reversed list (vector takes less memory, so
    ;; there is less GC), plus `length' comes naturally.  In-place
    ;; `nreverse' would be faster still, but BODY would be able to see
    ;; that, even if the modification was undone before we return.
    `(let* ((,v (vconcat ,list))
            (,i (length ,v))
            it it-index)
       (ignore it it-index)
       (while (> ,i 0)
         (setq ,i (1- ,i) it-index ,i it (aref ,v ,i))
         ,@body))))