mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 15:14:12 +00:00
12 lines
377 B
Plaintext
12 lines
377 B
Plaintext
;; Functions to calculate factorial
|
|
|
|
;; Recursive version, not tail call optimized
|
|
(def recFact (fn (n) (if (< n 2) 1 (* n (recFact (dec n))))))
|
|
|
|
;; Apply version
|
|
(def applyFact (fn (n) (if (< n 2) 1 (apply * (range 1 (inc n))))))
|
|
|
|
;; Add documentation
|
|
(doc recFact "Calculate the factor of n recursively.")
|
|
(doc applyFact "Calculate the factor of n iteratively using apply.")
|