Programming-Idioms

History of Idiom 31 > diff from v42 to v43

Edit summary for version 43 :
[Clojure] formatting

Version 42

2017-12-21, 03:16:17

Version 43

2017-12-21, 03:23:16

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Code
(defn f [i]
  (loop [cnt i, acc 1N]
    (if (zero? cnt)
      acc
      (recur (dec cnt) (* cnt acc)))))
Code
(defn f [i]
  (loop [cnt i, acc 1N]
    (if (zero? cnt) acc
      (recur (dec cnt) (* cnt acc)))))
Comments bubble
This supports arbitrary-precision and self tail call optimization.
Comments bubble
This supports arbitrary-precision and self tail call optimization.
Doc URL
https://clojuredocs.org/clojure.core/recur#example-542692d0c026201cdc326ea6
Doc URL
https://clojuredocs.org/clojure.core/recur#example-542692d0c026201cdc326ea6
Origin
https://clojuredocs.org/clojure.core/recur#example-542692d0c026201cdc326ea6
Origin
https://clojuredocs.org/clojure.core/recur#example-542692d0c026201cdc326ea6
Demo URL
https://ideone.com/wk8obN
Demo URL
https://ideone.com/wk8obN