areduce

clojure.core

  • (areduce a idx ret init expr)
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.

1 Example top

  • ;; This should be about as quick as summing up a array of floats in java.
    
    user=> (defn asum [#^floats xs]
             (areduce xs i ret (float 0)
                      (+ ret (aget xs i))))
    
    user=> (asum (float-array [1 2 3]))
    6.0
    
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/amap

    Maps an expression across an array a, using an index named idx, and

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:4582 top

(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]
     (loop  [~idx 0 ~ret ~init]
       (if (< ~idx  (alength a#))
         (recur (unchecked-inc ~idx) ~expr)
         ~ret))))
Vars in clojure.core/areduce:
Used in 0 other vars

Comments top

No comments for areduce. Log in to add a comment.