ClassCastException java.lang.Long不能转换为clojure.lang.IFn [英] ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn

查看:550
本文介绍了ClassCastException java.lang.Long不能转换为clojure.lang.IFn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,需要的年数和薪水,然后递归加倍的薪水,直到几年用尽。但是,我一直收到此错误:

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:


ClassCastException java.lang.Long无法转换为clojure.lang.IFn

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

代码

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



我对Clojure很新,所以我确定它的东西很简单,

I'm very new to Clojure so I'm sure its something simple, but I just can't seem to figure it out.

推荐答案

错误的意思不应该太难理解:数字

The error's meaning shouldn't be too hard to sort out: a number is being used where a function is expected.

Clojure中的括号不是分组结构,它们主要用于调用函数调用。如果将(salary)更改为 salary ,您将返回该数字而不是尝试将其调用为无参数函数。

Parenthesis in Clojure are not a grouping construct, they are used primarily to invoke function calls. If you change (salary) to salary you will return the number rather than attempting to call it as a no-argument function.

这篇关于ClassCastException java.lang.Long不能转换为clojure.lang.IFn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆