2015-06-03 49 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