More complete example:

(defn get-some-ints []
  (int-array [1 2 3]))

(set! *warn-on-reflection* true)

;; causes a reflection warning
(let [xs (get-some-ints)]
  (aget xs 0))

;; do not cause reflection warnings
(let [xs (ints (get-some-ints))]
  (aget xs 0))

(let [xs ^ints (get-some-ints)]
  (aget xs 0))

(let [^ints xs (get-some-ints)]
  (aget xs 0))

Cheers,
Michał


On 20 July 2013 11:25, Michał Marczyk <michal.marc...@gmail.com> wrote:
> I think it's more about clojure.core/{ints,longs,...}. These are
> basically tools for removing reflection:
>
> (let [xs (ints (get-some-ints))]
>    (aget xs 0)) ; no reflection here thanks to the cast
>
> Cheers,
> Michał
>
>
> On 20 July 2013 10:47, Mikera <mike.r.anderson...@gmail.com> wrote:
>> Do you mean something like (int-array [1 2 3 4])?
>>
>> This is a cast-like operation that produces a primitive array of ints,
>> exactly like int[] in Java. You can then use it with array operations like
>> "aget".
>>
>> If you want to type-hint int-array parameters then you need to use something
>> like "^ints", e.g.
>>
>> (defn third-int-in-array [^ints xs]
>>      (aget xs 2))
>>
>> On Saturday, 20 July 2013 02:28:15 UTC+1, Brian Craft wrote:
>>>
>>> I'm unable to find any examples of primitive array casts, and the docs are
>>> not helpful. Can someone point me to examples or docs that explain what they
>>> do?
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with your
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to