試行此代碼段似乎並沒有被工作完全正確..瞭解復發
(defn- multiple_of?
[div num]
(= (mod num div) 0))
(defn sum_of_multiples_from
([start] (sum_of_multiples_from start 0))
([start total]
(if (<= start 0)
total
(recur (dec start) (or (multiple_of? 3 start) (multiple_of? 5 start)
(+ total start) start)))))
我收到以下錯誤:
java.lang.Boolean cannot be cast to java.lang.Number
我猜測它做與:
(recur (dec start) (or (multiple_of? 3 start) (multiple_of? 5 start)
(+ total start)
start)))))
但我不知道爲什麼,我是clojure新手,所以我試圖得到一個復發的把握。
請問_clojure_方式是,如果包裝在一個?像'(如果(或多重?3開始)(multiple_of?5開始))(+總開始)開始)'或者我離開? – deano
'(if(或multiple_of?3 start)...)'將測試函數'multiple_of?'而不調用它。你需要parens來打電話。 '(if(或(multiple_of?3 start)(multiple_of?5 start))...)' – noisesmith