0
votes

I want to check whether the number of a given list is 0 or not, but my code returns EmptyList cannot be cast to clojure.lang.IFn.

(defn fun [ls]
    (println ls)
    (println "hello")
    (println (count ls))
    (if (<= 0 (count (ls))) true
         (println "testing")))

#'user/fun
user=> (fun '())
()
hello
0

ClassCastException clojure.lang.PersistentList$EmptyList cannot be cast to clojure.lang.IFn  user/fun (form-init4069658807942123979.clj:5)

Is there any one can help me out? Thank you so much!

2

2 Answers

1
votes

this expression:

(count (ls))

should be

(count ls)

It's trying to call the current value of ls as a function. When ls is the value () then it complains about trying to call the empty list as a function, which it is not.