This example is probably the most elegant factorial function that I've seen to date, in the Clojure JVM language.
There's a longer discussion on the google group too. Other languages that support "reduce" such has Python and Lisp clones probably might achieve the same succint syntax.
(defn factorial [n]
(reduce * (range 1 (inc n))))
There's a longer discussion on the google group too. Other languages that support "reduce" such has Python and Lisp clones probably might achieve the same succint syntax.
No comments:
Post a Comment