Skip to content

Commit 74164b4

Browse files
anmonteirodnolen
authored andcommitted
CLJS-1411: make-array signature differs from clojure
- added new function signature to match that of Clojure's - added warning about the computational cost of creating multi-dimensional arrays in JavaScript to the docstring
1 parent baaa73a commit 74164b4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,20 @@
354354
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; arrays ;;;;;;;;;;;;;;;;
355355

356356
(defn ^array make-array
357-
"Construct a JavaScript array of specified size. Accepts ignored type
358-
argument for compatibility with Clojure."
357+
"Construct a JavaScript array of the specified dimensions. Accepts ignored
358+
type argument for compatibility with Clojure. Note that there is no efficient
359+
way to allocate multi-dimensional arrays in JavaScript; as such, this function
360+
will run in polynomial time when called with 3 or more arguments."
359361
([size]
360362
(js/Array. size))
361363
([type size]
362-
(make-array size)))
364+
(make-array size))
365+
([type size & more-sizes]
366+
(let [dims more-sizes
367+
dimarray (make-array size)]
368+
(dotimes [i (alength dimarray)]
369+
(aset dimarray i (apply make-array nil dims)))
370+
dimarray)))
363371

364372
(defn aclone
365373
"Returns a javascript array, cloned from the passed in array"

0 commit comments

Comments
 (0)