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}}:

Clojure:

user=> (aget (to-array [nil 1]) -1) ArrayIndexOutOfBoundsException -1 clojure.lang.RT.aget (RT.java:2336) 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 (RT.java:2336)

ClojureScript

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
by

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": https://github.com/clojure/clojure/commit/742619e583400400e69cd46ab9e9536c10afb738

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2149 (reported by mfikes)
...