function/macro | since v0.0-1211 | clojure.core/make-array | Edit |
(make-array size)
(make-array type size)
(make-array type size & more-sizes)
Creates an empty JavaScript array of size size
.
Construct a JavaScript array of the specified dimensions. Accepts ignored type argument for compatibility with Clojure. Note that there is no efficient way to allocate multi-dimensional arrays in JavaScript; as such, this function will run in polynomial time when called with 3 or more arguments.
(defn ^array make-array
([size]
(js/Array. size))
([type size]
(make-array size))
([type size & more-sizes]
(let [dims more-sizes
dimarray (make-array size)]
(dotimes [i (alength dimarray)]
(aset dimarray i (apply make-array nil dims)))
dimarray)))
(core/defmacro make-array
([size]
(vary-meta
(if (core/number? size)
`(array ~@(take size (repeat nil)))
`(js/Array. ~size))
assoc :tag 'array))
([type size]
`(cljs.core/make-array ~size))
([type size & more-sizes]
(vary-meta
`(let [dims# (list ~@more-sizes)
dimarray# (cljs.core/make-array ~size)]
(dotimes [i# (alength dimarray#)]
(aset dimarray# i# (apply cljs.core/make-array nil dims#)))
dimarray#)
assoc :tag 'array)))