In clojure, calling reduce *en on an empty collection returns 1. This is pretty surprising.
I made this discovery by creating a factor function defined as follows:
(defn factorial [n] (reduce * (take-while
(factorial 0)returns correctly 1, without the need to write a special case for zero. Why?
Denis source
share