ClojureScript

*-array fns require a seq, rather than any seqable

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code

Description

The *-array functions in Clojure accept anything seqable:

user=> (int-array [1 2 3])
#<int[] [I@770c30be>
user=> (object-array [1 2 3])
#<Object[] [Ljava.lang.Object;@7b08c2a1>
user=> (seq (object-array {:a 5}))
([:a 5])

Not so in ClojureScript:

cljs.user=> (int-array [1 2 3])
"Error evaluating:" (int-array [1 2 3]) :as "cljs.core.int_array.call(null,cljs.core.PersistentVector.fromArray([1,2,3], true));\n"
#<Error: int-array called with something other than size or ISeq>

Activity

Hide
Chas Emerick added a comment -

Patch attached that simply seq's any non-number passed to the *-array fn. The error messages if you pass something unacceptable are less friendly, but the API is equivalent to Clojure's.

Aside: it seems all the *-array fns are identical, outside of the name. Is that to eventually support typed arrays, or can we safely define object-array once, and alias it to double-array, int-array, etc.?

Show
Chas Emerick added a comment - Patch attached that simply seq's any non-number passed to the *-array fn. The error messages if you pass something unacceptable are less friendly, but the API is equivalent to Clojure's. Aside: it seems all the *-array fns are identical, outside of the name. Is that to eventually support typed arrays, or can we safely define object-array once, and alias it to double-array, int-array, etc.?
Hide
Chas Emerick added a comment -

Awesome, thanks! Any comment on the P.S. above, "…it seems all the *-array fns are identical, outside of the name. Is that to eventually support typed arrays, or can we safely define object-array once, and alias it to double-array, int-array, etc.?"

Show
Chas Emerick added a comment - Awesome, thanks! Any comment on the P.S. above, "…it seems all the *-array fns are identical, outside of the name. Is that to eventually support typed arrays, or can we safely define object-array once, and alias it to double-array, int-array, etc.?"

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: