• (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:4566 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 0]
       (if (< ~idx  (alength a#))
         (do
           (aset ~ret ~idx ~expr)
           (recur (unchecked-inc ~idx)))
         ~ret))))
Vars in clojure.core/amap:
Used in 0 other vars

Comments top

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