Yes, integer literals are longs by default in 1.3. As noted, this works:
(aset-int (make-array Integer/TYPE 3 4 5) 1 2 3 -1)
My intuition says this should work as well, but it doesn't:
(aset ^ints (make-array Integer/TYPE 3 4 5) 1 2 3 (int -1))
IllegalArgumentException argument type mismatch
java.lang.reflect.Array.set
The reason why becomes apparent on examining the source of aset:
(defn aset
{:inline (fn [a i v] `(. clojure.lang.RT (aset ~a (int ~i) ~v)))
:inline-arities #{3}
:added "1.0"}
([array idx val]
(. Array (set array idx val))
val)
([array idx idx2 & idxv]
(apply aset (aget array idx) idx2 idxv)))
When given more than three arguments, `aset` uses `apply`, which does not
accept primitive arguments. Thus, for multidimensional arrays, `aset`
cannot be called with primitive arguments.
With single-dimensional arrays, `aset` works on primitives as expected:
(aset (int-array 3) 1 -1)
-Stuart Sierra
clojure.com
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en