Skip to content

Instantly share code, notes, and snippets.

@arademaker
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arademaker/c1ba0f881527ed70d6d7 to your computer and use it in GitHub Desktop.
Save arademaker/c1ba0f881527ed70d6d7 to your computer and use it in GitHub Desktop.
Fibonacci functions in CL. Used in the presentation of Chapter 0 of http://books.google.com/books?id=3sCxQgAACAAJ
(defun fib1 (n)
(cond
((equal n 0) 0)
((equal n 1) 1)
(t (+ (fib1 (- n 1))
(fib1 (- n 2))))))
(defun fib2 (n)
(labels ((calc-fib (n a b)
(if (= n 0)
a
(calc-fib (- n 1) b (+ a b)))))
(calc-fib n 0 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment