Skip to content

Commit

Permalink
* devnotes/corelib.org: CLJS-16: missing array ops
Browse files Browse the repository at this point in the history
  • Loading branch information
David Nolen authored and David Nolen committed Apr 21, 2012
1 parent 8b74d8d commit 0b7d04b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
12 changes: 6 additions & 6 deletions devnotes/corelib.org
Expand Up @@ -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
Expand Down Expand Up @@ -284,7 +284,7 @@ does what?
* intern
* DONE interpose
* DONE into
* TODO into-array
* DONE into-array
* ints
* io!
* DONE isa?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -369,7 +369,7 @@ does what?
* TODO num
* DONE number?
* TODO numerator
* TODO object-array
* DONE object-array
* DONE odd?
* DONE or
* DONE parents
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/cljs/cljs/core.cljs
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0b7d04b

Please sign in to comment.