Exercism.io challenge : An unexpected error occurred: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to clojure.lang.IFn

Hello,

I try to solve a exercisim.io challenge.
The code so far looks like this :

(defn annual-balance-update
  "Returns the annual balance update, taking into account the interest rate."
  [balance]
  (* balance (/ interest-rate(balance) 100))) 

but I see this error message :

An unexpected error occurred:
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to clojure.lang.IFn

What do I do wrong?

1 Like

This part is wrong: interest-rate(balance). If interest-rate is a function and you wanted to call it on balance, then it should be (interest-rate balance).

That specific error message is due to the (balance) part. Clojure treats it as calling a function that’s referred to by balance. Since balance is, apparently, an instance of BigDecimal, JVM throws that error.

2 Likes

Thanks, still a lot to learn.
Problem solved

2 Likes

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