0

我写的这段代码给了我错误:

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)))

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

4

1 回答 1

3

+ 在错误的地方:

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

应该:

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

y1 也一样。由于您在其他地方有这个正确的,它看起来像一个简单的错字。

虽然)))))))在 clojure 代码中看到是很正常((的,但再看一眼就会出现警告。

于 2015-06-03T20:57:35.593 回答