I have a Clojure seq containing 3 functions. Why (rest my-seq) gives an exception "cannot be excellent"?

In the process of debugging a larger function, I created a simpler function to check where the error is:

(defn foo [a-val p1 p2 & rest]
  (loop [curr-preds   (cons p1 (cons p2 rest))]
    (let [first-pred   (first curr-preds)
          first-bool   (first-pred a-val)
          second-bool  ((second curr-preds) a-val)
          third-bool  ((last curr-preds) a-val)]
      (println "\n\nLogical values: " first-bool second-bool third-bool)
      (println "Is it a seq?"  (seq? curr-preds))
      (if (empty? curr-preds)
        first-bool
        #_(recur (rest curr-preds))
          ))))

p1, p2, and the set of functions at rest are all predicates (for example, odd?). I wrote this with the expectation that it will always be called up to 3 predicates.

When I take out #_the next line, I get the following error:

java.lang.ClassCastException: clojure.lang.ArraySeq cannot be cast to clojure.lang.IFn
/Users/gr/temp/LTtemp1.clj:166 user/foo
          RestFn.java:467 clojure.lang.RestFn.invoke

Through expressions, printlnI found that:

  • curr-preds is this seqcontaining 3 predicates as expected

  • calling each pred on a-valreturns the expected result

  • curr-predsessentially a seq

: rest seqs, not-cast-cast? .

+3
1

rest, . rest , , clojure.core/rest.

+5

All Articles