RosettaCodeData/Task/Anonymous-recursion/Common-Lisp/anonymous-recursion-3.lisp

10 lines
293 B
Common Lisp
Raw Permalink Normal View History

2013-10-27 22:24:23 +00:00
(defun fib (number)
"Fibonacci sequence function."
(if (< number 0)
(error "Error. The number entered: ~A is negative" number)
2015-02-20 00:35:01 -05:00
(labels ((fib (n a b)
2013-10-27 22:24:23 +00:00
(if (= n 0)
a
2015-02-20 00:35:01 -05:00
(fib (- n 1) b (+ a b)))))
(fib number 0 1))))