store/[org.clojure/clojure "1.8.0"] clj::clojure.core/areduce

Official Documentation

Add notes
Arities
==================================================
   [a idx ret init expr]

Docstring
==================================================
  Reduces an expression across an array a, using an index named idx,
  and return value named ret, initialized to init, setting ret to the 
  evaluation of expr at each step, returning ret.

Source

(defmacro areduce
  "Reduces an expression across an array a, using an index named idx,
  and return value named ret, initialized to init, setting ret to the 
  evaluation of expr at each step, returning ret."
  {:added "1.0"}
  [a idx ret init expr]
  `(let [a# ~a l# (alength a#)]
     (loop  [~idx 0 ~ret ~init]
       (if (< ~idx l#)
         (recur (unchecked-inc-int ~idx) ~expr)
         ~ret))))

Example 1

Edit
;; This should be about as quick as summing up a array of floats in java.

(defn asum [#^floats xs]
  (areduce xs i ret (float 0)
           (+ ret (aget xs i))))
;; => #'user/asum

(asum (float-array [1 2 3]))
;; => 6.0

Uses on crossclj