java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn

I have this code :

(ns triangle)

(defn have-valid-lengths?
  "two sides of the triangle must be more then the 3th side"
  [s1 s2 s3]
  (or (> (+ s1 s2) s3) (> (+ s1 s3) s2) (> (+ s2 s3) s1)))

(defn no-zero-sides?
  " a triangle does not have a side with the length of zero"
  [s1 s2 s3]
  (not (zero? s1 s2 s3)))

(defn is-valid?
  " a triangle is valid when no sides have a length of zero and the sides are all valid"
  [s1 s2 s3] 
  (and (no-zero-sides?(s1 s2 s3)) (have-valid-lengths?(s1 s2 s3))))

(defn equilateral? 
  "a equilateral is a triangle which sides have the same length and is valid"
  [s1 s2 s3]
  (and (== s1 s2) (== s2 s3) (== s1 s3) (is-valid? s1 s2 s3) ))

(defn isosceles? [] ;; <- arglist goes here
  ;; your code goes here
)

(defn scalene? [] ;; <- arglist goes here
  ;; your code goes here
)

but now I see this error message :

java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn

Can someone help me figure out what I did wrong ?

You are calling s1 here and it’s a long – ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn means β€œI expected a function but I got a long!”

1 Like

Thanks. problem solved

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.