Fibonacci numbers in Lisp
Example for versions
Corman Common Lisp 3.0,
SBCL 1.0.1,
SBCL 1.0.29,
clisp 2.47,
gcl 2.6.6
This example uses recursive definition of Fibonacci numbers and expands use of loop
macro to finally
clause (expression evaluated after the loop is done).
(defun fibonacci (n)
(if (< n 3)
1
(+ (fibonacci (- n 1)) (fibonacci (- n 2))) ) )
(loop for i from 1 to 16
do (format t "~D, " (fibonacci i))
finally (format t "...~%") )
Comments
]]>blog comments powered by Disqus
]]>