[英]Clojure : java.lang.Character cannot be cast to clojure.lang.IFn
[英]java.lang.Double cannot be cast to clojure.lang.IFn issue
我正在為一個賦值編寫一個基本的指數函數,但我不知道為什么會出現此錯誤。 這是我的代碼:
(def epsilon 0.000001)
(def exponentialing
(fn [F S T x]
(if
(<= T epsilon)
S
(recur (+ F 1) (+ S T) (* T(/ x F)) x))))
(def exp
(fn [x]
(exponentialing 1.0 0.0 1.0 x)))
我在最后一行收到錯誤消息,我假設它與參數點中的雙精度數或x有關
看來您在recur
行中缺少空格。 我還簡化了從def
到defn
功能。 另外,您無法在原始版本中調用exp
:
(ns clj.core
(:require [tupelo.core :as t] ))
(t/refer-tupelo)
(def epsilon 0.000001)
(defn exponentialing
[F S T x]
(if
(<= T epsilon)
S
(recur (+ F 1) (+ S T) (* T (/ x F)) x)))
(defn exp
[x]
(exponentialing 1.0 0.0 1.0 x))
(spyx (exp 3))
> lein run
(exp 3) => 20.085536488379084
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.