Share your thoughts in the 2021 Clojure Community Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

Like CLJS-2113, but for {{aget}}:


user=> (aget (to-array [nil 1]) -1) ArrayIndexOutOfBoundsException -1 clojure.lang.RT.aget ( user=> (aget (to-array [nil 1]) 0) nil user=> (aget (to-array [nil 1]) 0.5) nil user=> (aget (to-array [nil 1]) 1) 1 user=> (aget (to-array [nil 1]) 1.5) 1 user=> (aget (to-array [nil 1]) 2) ArrayIndexOutOfBoundsException 2 clojure.lang.RT.aget (


cljs.user=> (aget (to-array [nil 1]) -1) nil cljs.user=> (aget (to-array [nil 1]) 0) nil cljs.user=> (aget (to-array [nil 1]) 0.5) nil cljs.user=> (aget (to-array [nil 1]) 1) 1 cljs.user=> (aget (to-array [nil 1]) 1.5) nil cljs.user=> (aget (to-array [nil 1]) 2) nil

Also note that Clojure acts as if rounding indices down to the nearest integer while ClojureScript does not:

(aget (to-array [1 2]) 0.5)

yields {{1}} in Clojure and {{nil}} in ClojureScript.

(Presumably, similar results hold for {{aset}}.)

2 Answers

0 votes

Comment made by: mfikes

The fact that Clojure's {{aget}} happens to work on non-integer indices may not be intentional. An {{int}} cast may be present only to ease interop with the default use of {{long}} integral values in Clojure, and while this cast causes the observed behavior (rounding down of passed {{double}} s), this may not reflect the intended API.

Here is a commit that speaks to "hints":

0 votes
Reference: (reported by mfikes)