madlisp/mad/fact.mad

8 lines
231 B
Plaintext
Raw Normal View History

2020-06-06 09:25:49 +00:00
;; Functions to calculate factorial
2020-06-08 02:55:29 +00:00
;; Recursive version, not tail call optimized
2020-10-17 07:18:16 +00:00
(def recFact (fn (n) (if (< n 2) 1 (* n (recFact (dec n))))))
2020-06-06 09:25:49 +00:00
;; Apply version
2020-10-17 07:18:16 +00:00
(def applyFact (fn (n) (if (< n 2) 1 (apply * (range 1 (inc n))))))