我敢肯定之前我的 alength
是可以用的,但是现在我不太清楚我哪里出了问题:
user=> (alength '(1 2 3))
IllegalArgumentException No matching method found: alength clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:79)
user=> (alength [1 2 3])
IllegalArgumentException No matching method found: alength clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:79)
user=> (doc alength)
-------------------------
clojure.core/alength
([array])
Returns the length of the Java array. Works on arrays of all
types.
nil
在Clojure中,我应该如何获取列表/数组的长度?
count
命令也适用于数组。 只有在速度至关重要的代码中,您已经知道自己拥有一个数组并且需要直接访问时,才需要使用alength
命令。在这种情况下,使用count
命令会更慢,因为它更通用。 - kotarak