You're viewing version 1.2.0 of areduce. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

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:4124 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 (int 0) ~ret ~init]
       (if (< ~idx  (alength a#))
         (recur (unchecked-inc ~idx) ~expr)
         ~ret))))
Vars in clojure.core/areduce: defmacro < alength apply concat int let list loop seq unchecked-inc vector
Used in 0 other vars

Comments top

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