Skip to content

Instantly share code, notes, and snippets.

@ShigekiKarita
Last active August 29, 2015 14:04
Show Gist options
  • Save ShigekiKarita/30859cd736f5622b11e5 to your computer and use it in GitHub Desktop.
Save ShigekiKarita/30859cd736f5622b11e5 to your computer and use it in GitHub Desktop.
How to get 10th Fibonacci number in Common Lisp
;; recur
(defun fib (i &optional (a 1) (b 0))
(if (= i 1)
a
(fib (1- i) (+ a b) a)))
(fib 10)
;; do macro
(do ((i 1 (1+ i))
(a 0 b)
(b 1 (+ b a)))
((< 10 i) a))
;; loop macro
(loop for i from 1 to 10
and a = 0 then b
and b = 1 then (+ b a)
finally (return a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment