Clojure length of sequence
As the docstring says, alength
works on Java™ arrays, such as a String[]
or Integer[]
, which is definitely an incompatible type with Clojure lists or vectors, for which you want to use count
:
user=> (def x '(1 2 3))
#'user/x
user=> (def xa (to-array x))
#'user/xa
user=> (class x)
clojure.lang.PersistentList
user=> (class xa)
[Ljava.lang.Object;
user=> (alength xa)
3
user=> (alength x)
java.lang.IllegalArgumentException: No matching method found: alength (NO_SOURCE_FILE:0)
user=> (count x)
3
[Ljava.lang.Object;
is the weird way toString
is defined to output for native Object
arrays.
Try using count
:
(count '(1 2 3))
=> 3
(count [1 2 3])
=> 3