You're viewing version 1.2.0 of amap. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (amap a idx ret expr)
Maps an expression across an array a, using an index named idx, and
return value named ret, initialized to a clone of a, then setting
each element of ret to the evaluation of expr, returning the new
array ret.

1 Example top

  • (def an-array (int-array 25000 (int 0)))
    
    user=> (time (amap ^ints an-array 
                       idx 
                       ret 
                       (+ (int 1) 
                          (aget ^ints an-array idx))))
    
    "Elapsed time: 14.708653 msecs"
    
    ;; Note: without type hinting the performance of would not be good.
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/areduce

    Reduces an expression across an array a, using an index named idx,

  • 0
    clojure.core/map

    Returns a lazy sequence consisting of the result of applying f to the

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:4108 top

(defmacro amap
  "Maps an expression across an array a, using an index named idx, and
  return value named ret, initialized to a clone of a, then setting 
  each element of ret to the evaluation of expr, returning the new 
  array ret."
  {:added "1.0"}
  [a idx ret expr]
  `(let [a# ~a
         ~ret (aclone a#)]
     (loop  [~idx (int 0)]
       (if (< ~idx  (alength a#))
         (do
           (aset ~ret ~idx ~expr)
           (recur (unchecked-inc ~idx)))
         ~ret))))
Used in 1 other vars add-core-ns

Comments top

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