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

前端 未结 4 1768
一向
一向 2020-12-30 19:17

I have a function that takes the number of years and salary, then recursively doubles the salary until years is exhausted. However, I keep getting this error:

4条回答
  •  Happy的楠姐
    2020-12-30 20:08

    You need to remove the brackets from around salary in your if condition:

    (if (= years 0)
            salary
            (calculate-salary (- years 1) (* salary 2))
    

    the form (f arg1 arg2 ..) attempts to call f as a function with arg1, arg2 ... as arguments. Therefore (salary) attempts to invoke salary (a long) as a function with no arguments, hence the error.

提交回复
热议问题