Source

snippets / alg / factorial.scm

Full commit
#!/usr/bin/guile
!#

;(define (fact n)
;	(if (= n 0) 1 (* n (fact(- n 1)))))

(define (factorial n)
	(define (fact-iter product count max)
		(if (> count max) product
			(fact-iter (* product count) (+ count 1) max)))
	(fact-iter 1 1 n))

(display (factorial 10))
(newline)