2015-06-03 27 views
0

此代码,我写给我的错误:Clojure的正常化功能运行时错误

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

这意味着我使用的数,其中一个函数的预期。

我认为它与clojure.math.numeric-tower的expt函数有关,但我不确定。神秘的错误消息FTL。

(ns point-normalize.core 
    (:require [clojure.math.numeric-tower :as math :only (sqrt expt)])) 

(defn normalize [x y] 
    (let [x1 (/ x (math/sqrt ((math/expt x 2)+ (math/expt y 2)))) 
     y1 (/ y (math/sqrt ((math/expt x 2)+ (math/expt y 2))))] 
    (x1 y1))) 

任何提示将不胜感激。谢谢。

回答

3

的+是在错误的地方在:

((math/expt x 2)+ (math/expt y 2))) 

应该是:

(+ (math/expt x 2) (math/expt y 2))) 

和Y1一样好。既然你在别处有这个问题,它看起来就像是一个简单的错字。

虽然在clojure代码中看到)))))))是非常正常的,但发生((的警告一眼。

+0

哦,我的天......我只是用C++编程,所以这就是为什么。谢谢! – Cody