2012-05-15 38 views
0

我在REPL中定義一個簡單的階乘函數:Clojure的REPL崩潰/復發構建

(defn factorial [n] 
    (loop [current n fact 1] 
    (if 
     (= current 1) 
     fact 
     (recur (dec current) (* current fact))))) 

功能工作正常。但是當我嘗試多次使用一個dotimes循環調用該函數時,REPL似乎停止工作。對於我輸入的任何表達式,我不會得到任何結果,並且必須重新啓動REPL。

(dotimes [x 10] 
    (println "Factorial of " x " is " (factorial x))) 

我使用的IntelliJ與香格里拉的Clojure插件(Clojure的版本1.3.0):與

我循環。

回答

1

我敢打賭,使用該函數定義計算(factorial 0)需要非常長的時間...