user6324692
user6324692

Reputation:

The error "clojure.lang.LazySeq cannot be cast to java.lang.Number"

In a Luminus app here's a part of an action which produces an error:

                 some-var (if (rem total-records page-size)
                                     (quot total-records page-size)
                                     (+ 1 (quot total-records page-size)))

the error being clojure.lang.LazySeq cannot be cast to java.lang.Number. And this doesn't:

some-var 123

How to fix the error?

Upvotes: 1

Views: 959

Answers (1)

Piotrek Bzdyl
Piotrek Bzdyl

Reputation: 13175

It looks that one of your variables total-pages and/or page-size is not a number but a seq whereas rem and quot functions require all its arguments to be numbers. Try to print it to console to check which one it is.

There is also another issue in your if expression: you want to use number value to test for truthiness. In Clojure any number value (including 0) is truthy (strictly speaking only niland false values are treated as falsehood) so you need to compare the result of rem to zero:

(if (zero? (rem a b)) 
  :truthy
  :falsey)

Upvotes: 1

Related Questions