William James
8/20/2015 5:32:00 PM
David Steuber wrote:
> CL-USER> (defun n! (n)
> (labels ((fact (x a)
> (if (< x 1)
> a
> (fact (1- x) (* x a)))))
> (fact n 1)))
> N!
>
> I also like the name better.
>
> CL-USER> (mapcar #'n! '(0 1 2 3 4 5 6 7 8 9 10))
> (1 1 2 6 24 120 720 5040 40320 362880 3628800)
>
> This also introduces the Common Lisp feature LABELS which allows you
> to define local functions that can call themselves recursively.
Gauche Scheme:
(define (n! n)
(let go ((n n) (a 1))
(if (< n 2)
a
(go (- n 1) (* a n)))))
(map n! (iota 11))
===>
(1 1 2 6 24 120 720 5040 40320 362880 3628800)
--
Arrogant and isolated, the elite treat the ordinary citizens of the empire as
slaves and potential enemies.
www.kolumbus.fi/aquilon/america-middle-class-and-the-end-of-growth.htm