Fibonacci numbers in Lisp
Example for versions
Corman Common Lisp 3.0,
clisp 2.47,
gcl 2.6.6
This example uses iterative definition of Fibonacci numbers, though expressed through recursive calls of fib-iter
.
(defun fibonacci (n)
(defun fib-iter (a b count)
(if (zerop count)
b
(fib-iter (+ a b) a (- count 1)) ) )
(fib-iter 1 0 n) )
(loop for i from 1 to 16
do (format t "~D, " (fibonacci i))
finally (format t "...~%") )
Comments
]]>blog comments powered by Disqus
]]>