Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tail-recursive Fibonacci numbers in Common Lisp
(defun fib (n)
(labels ((calc-fib (n a b)
(if (= n 0)
a
(calc-fib (- n 1) b (+ a b)))))
(calc-fib n 0 1)))
(time (print (fib 7000)))
366434830503723283227635896728160492185715439341759896262706987207280114599614526152053044740885086342851333937720801438606098584376372899095056033825107960458188127617648
439630978827568993068806323391496244577925210655496624507469829546295160700987649783441511835995330030762779087743459391817243909019805275976633115556130331941538448665875
113367934989079027834056981179027194590668556273530473374341075308297806336029119084263897552528237137625514625139073770774797947702482294838436466336818335492151234705854
827154728090873839417589043465226408479182333077269328866108345114427090779695990005117224442643471755382945481853638762026546985115627193770965426310539435270280830110342
495740505443289855351689552916713660362444791587432378032795204011880532527884702888478000351372675123176633429260114393334028014521369041992958201987034328371275338650330
779174410100898022841492469103704073386054730663565822108884580528522055691701523568506284269126884159083365298189844996272456235892106505571347914983448350547947756232111
875546791699814341126089145748433246683326437750109247056900191022745751456134839226815963856547592332694442642416195266808081341737280349475872783233388450598439414037223
575558750012302913355794850648784308559343577303219076693667107597304311585020946440826703894644256389422018773931805536475153773174336282160988894513327185167202072760588
83659104584529812229076091130643430114436305262385420314059450210042195431947096493318081320875
Real time: 0.055593 sec.
Run time: 0.039964 sec.
Space: 2244504 Bytes
GC: 2, GC time: 0.017957 sec.
@trendsetter37

This comment has been minimized.

Copy link

trendsetter37 commented Dec 14, 2014

Nice example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.