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

make-array

clojure.core

  • (make-array type len)
  • (make-array type dim & more-dims)
Creates and returns an array of instances of the specified class of
the specified dimension(s). Note that a class object is required.
Class objects can be obtained by using their imported or
fully-qualified name. Class objects for the primitive types can be
obtained using, e.g., Integer/TYPE.

2 Examples top

  • (make-array Integer/TYPE 3)
  • user=> (pprint (make-array Double/TYPE 3))
    [0.0, 0.0, 0.0]
    
    user=> (pprint (make-array Integer/TYPE 2 3))
    [[0, 0, 0], [0, 0, 0]]
    
    
    ;; Create an array of Threads, then show content and type
    user=> (def ar (make-array Thread 3))
    #'user/ar
    
    user=> (pprint ar)
    [nil, nil, nil]
    
    user=> (type ar)
    [Ljava.lang.Thread;
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3061 top

(defn make-array
  "Creates and returns an array of instances of the specified class of
  the specified dimension(s).  Note that a class object is required.
  Class objects can be obtained by using their imported or
  fully-qualified name.  Class objects for the primitive types can be
  obtained using, e.g., Integer/TYPE."
  {:added "1.0"}
  ([^Class type len]
   (. Array (newInstance type (int len))))
  ([^Class type dim & more-dims]
   (let [dims (cons dim more-dims)
         ^"[I" dimarray (make-array (. Integer TYPE)  (count dims))]
     (dotimes [i (alength dimarray)]
       (aset-int dimarray i (nth dims i)))
     (. Array (newInstance type dimarray)))))
Vars in clojure.core/make-array: aset-int defn dotimes int let nth type
Used in 0 other vars

Comments top

No comments for make-array. Log in to add a comment.