summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-10-17 23:58:53 +0000
committerRich Hickey <richhickey@gmail.com>2008-10-17 23:58:53 +0000
commit7c8af7266505c3425712f6b48b5f250114015c20 (patch)
tree68d1d12af6e24abaeb7f86c0be5a9a1f112aa46e /src
parente7e3ca9d005df867ee44609785b166d1043f77af (diff)
added optional type arg to into-array, patch from Stephen C. Gilardi
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/boot.clj16
-rw-r--r--src/jvm/clojure/lang/RT.java8
2 files changed, 16 insertions, 8 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj
index 80162e9b..94000c8f 100644
--- a/src/clj/clojure/boot.clj
+++ b/src/clj/clojure/boot.clj
@@ -1541,11 +1541,15 @@
(apply import (rest import-lists))))
(defn into-array
- "Returns an array of the type of the first element in coll,
- containing the contents of coll, which must be of a compatible
- type."
- [aseq]
- (. clojure.lang.RT (seqToTypedArray (seq aseq))))
+ "Returns an array with components set to the values in aseq. The array's
+ component type is type if provided, or the type of the first value in
+ aseq if present, or Object. All values in aseq must be compatible with
+ the component type. Class objects for the primitive types can be obtained
+ using, e.g., Integer/TYPE."
+ ([aseq]
+ (clojure.lang.RT/seqToTypedArray (seq aseq)))
+ ([type aseq]
+ (clojure.lang.RT/seqToTypedArray type (seq aseq))))
(defn into
"Returns a new coll consisting of to-coll with all of the items of
@@ -1819,7 +1823,7 @@
the specified dimension(s). Note that a class object is required.
Class objects can be obtained by using their imported or
fully-qualified name. Class objects for the primitive types can be
- obtained using, e.g., (. Integer TYPE)."
+ obtained using, e.g., Integer/TYPE."
([#^Class type len]
(. Array (newInstance type (int len))))
([#^Class type dim & more-dims]
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index 9982ebbf..2cb519cd 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -1079,8 +1079,12 @@ static public Object[] seqToArray(ISeq seq){
}
static public Object seqToTypedArray(ISeq seq) throws Exception{
- int len = length(seq);
- Object ret = Array.newInstance(len > 0 ? seq.first().getClass() : Object.class, len);
+ Class type = (seq != null) ? seq.first().getClass() : Object.class;
+ return seqToTypedArray(type, seq);
+}
+
+static public Object seqToTypedArray(Class type, ISeq seq) throws Exception{
+ Object ret = Array.newInstance(type, length(seq));
for(int i = 0; seq != null; ++i, seq = seq.rest())
Array.set(ret, i, seq.first());
return ret;