# [Lisp] Compute factorial in Clojure

Page 1 of 1

## 0 Replies - 1315 Views - Last Post: 13 December 2009 - 09:17 AM

Reputation: 9
• Posts: 120
• Joined: 11-July 09

# [Lisp] Compute factorial in Clojure

Posted 13 December 2009 - 09:17 AM

Description: example usage: user=> (factorial 10) 3628800This function computes the factorial of n in Clojure.
```(defn factorial
"Computes the factorial of n."
[n]
(if (< n 0) (throw (Exception. "Cannot find the factorial of a negative number.")))
(if (zero? 0) 1
(* n (factorial (dec n)))))
```

Is This A Good Question/Topic? 0

## Replies To: [Lisp] Compute factorial in Clojure

Reputation: 9
• Posts: 120
• Joined: 11-July 09

## Re: [Lisp] Compute factorial in Clojure

Posted 13 December 2009 - 09:17 AM

Description: example usage: user=> (factorial 10) 3628800This function computes the factorial of n in Clojure.
```(defn factorial
"Computes the factorial of n."
[n]
(if (< n 0) (throw (Exception. "Cannot find the factorial of a negative number.")))
(if (zero? n) 1
(* n (factorial (dec n)))))

(def factorial (memoize factorial))
```