Permalink
Browse files

add int-array for compat

  • Loading branch information...
swannodette committed Feb 21, 2013
1 parent b7dcafc commit 3c0fb6ef5f88b7792e75e535c02a183cab9e6de2
Showing with 22 additions and 1 deletion.
  1. +1 −1 devnotes/corelib.org
  2. +21 −0 src/cljs/cljs/core.cljs
View
@@ -278,7 +278,7 @@ macro currently expands into extend call
* DONE instance?
does what?
* DONE int
-* int-array
+* DONE int-array
* DONE integer?
* DONE interleave
* intern
View
@@ -2131,6 +2131,27 @@ reduces them without incurring seq initialization"
(recur (inc i) (next xs))))
ret))
+(defn int-array
+ ([size-or-seq]
+ (cond
+ (number? size-or-seq) (int-array size-or-seq nil)
+ (seq? size-or-seq) (into-array size-or-seq)
+ :else (throw (js/Error. "int-array called with something other than size or ISeq"))))
+ ([size init-val-or-seq]
+ (let [a (make-array size)]
+ (if (seq? init-val-or-seq)
+ (let [s (seq init-val-or-seq)]
+ (loop [i 0 s s]
+ (if (and s (< i size))
+ (do
+ (aset a i (first s))
+ (recur (inc i) (next s)))
+ a)))
+ (do
+ (dotimes [i size]
+ (aset a i init-val-or-seq))
+ a)))))
+
(defn long-array
([size-or-seq]
(cond

0 comments on commit 3c0fb6e

Please sign in to comment.