Skip to content
Browse files

* devnotes/corelib.org: CLJS-16: missing array ops

  • Loading branch information...
1 parent 8b74d8d commit 0b7d04bad801f49db9a7c3bf3004184c07fe6843 David Nolen committed Apr 21, 2012
Showing with 31 additions and 6 deletions.
  1. +6 −6 devnotes/corelib.org
  2. +25 −0 src/cljs/cljs/core.cljs
View
12 devnotes/corelib.org
@@ -198,7 +198,7 @@ For macros only, uses clojure.core version
* DONE dotimes
* DONE doto
* TODO double
-* TODO double-array
+* DONE double-array
* TODO doubles
* DONE drop
* DONE drop-last
@@ -284,7 +284,7 @@ does what?
* intern
* DONE interpose
* DONE into
-* TODO into-array
+* DONE into-array
* ints
* io!
* DONE isa?
@@ -315,12 +315,12 @@ does what?
* loaded-libs
* locking
* DONE long
-* TODO long-array
+* DONE long-array
* TODO longs
* DONE loop
* macroexpand
* macroexpand-1
-* TODO make-array
+* DONE make-array
* DONE make-hierarchy
* DONE map
* DONE map-indexed
@@ -369,7 +369,7 @@ does what?
* TODO num
* DONE number?
* TODO numerator
-* TODO object-array
+* DONE object-array
* DONE odd?
* DONE or
* DONE parents
@@ -519,7 +519,7 @@ as macro
* thread-bound?
* DONE time
* DONE to-array
-* TODO to-array-2d
+* DONE to-array-2d
* DONE trampoline
* transient
* DONE tree-seq
View
25 src/cljs/cljs/core.cljs
@@ -99,6 +99,20 @@
[array]
(.-length array))
+(declare reduce)
+
+(defn into-array [coll]
+ (reduce (fn [a x] (.push a x) a) (array) coll))
+
+(defn long-array [coll]
+ (array))
+
+(defn double-array [coll]
+ (array))
+
+(defn object-array [coll]
+ (array))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;; core protocols ;;;;;;;;;;;;;
(defprotocol IFn
@@ -1417,6 +1431,17 @@ reduces them without incurring seq initialization"
(recur (next s)))
ary))))
+(defn to-array-2d
+ "Returns a (potentially-ragged) 2-dimensional array
+ containing the contents of coll."
+ [coll]
+ (let [ret (make-array (count coll))]
+ (loop [i 0 xs (seq coll)]
+ (when xs
+ (aset ret i (to-array (first xs)))
+ (recur (inc i) (next xs))))
+ ret))
+
(defn- bounded-count [s n]
(loop [s s i n sum 0]
(if (and (pos? i)

0 comments on commit 0b7d04b

Please sign in to comment.
Something went wrong with that request. Please try again.