Skip to content

Commit 3c0fb6e

Browse files
committed
add int-array for compat
1 parent b7dcafc commit 3c0fb6e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

devnotes/corelib.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ macro currently expands into extend call
278278
* DONE instance?
279279
does what?
280280
* DONE int
281-
* int-array
281+
* DONE int-array
282282
* DONE integer?
283283
* DONE interleave
284284
* intern

src/cljs/cljs/core.cljs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,27 @@ reduces them without incurring seq initialization"
21312131
(recur (inc i) (next xs))))
21322132
ret))
21332133

2134+
(defn int-array
2135+
([size-or-seq]
2136+
(cond
2137+
(number? size-or-seq) (int-array size-or-seq nil)
2138+
(seq? size-or-seq) (into-array size-or-seq)
2139+
:else (throw (js/Error. "int-array called with something other than size or ISeq"))))
2140+
([size init-val-or-seq]
2141+
(let [a (make-array size)]
2142+
(if (seq? init-val-or-seq)
2143+
(let [s (seq init-val-or-seq)]
2144+
(loop [i 0 s s]
2145+
(if (and s (< i size))
2146+
(do
2147+
(aset a i (first s))
2148+
(recur (inc i) (next s)))
2149+
a)))
2150+
(do
2151+
(dotimes [i size]
2152+
(aset a i init-val-or-seq))
2153+
a)))))
2154+
21342155
(defn long-array
21352156
([size-or-seq]
21362157
(cond

0 commit comments

Comments
 (0)