Hello everyone,
I'm trying to learn LISP after about 7 years not doing any kind of coding. I am slowly working my way through the Practical Common LISP book and have run into an example that I can't seem to follow.
In chapter 7, there is an example of a DO loop which results in the 11th Fibonacci number, 55.
Here is the code:
I'm clearly not following it through correctly on paper; can anyone break this down so I can see where I'm going wrong?
Thanks so much for the help!
I'm trying to learn LISP after about 7 years not doing any kind of coding. I am slowly working my way through the Practical Common LISP book and have run into an example that I can't seem to follow.
In chapter 7, there is an example of a DO loop which results in the 11th Fibonacci number, 55.
Here is the code:
(do ((n 0 (1+ n))
(cur 0 next)
(next 1 (+ cur next)))
((= 10 n) cur))
When I throw that into the REPL I get 55, which makes sense. However, when I try to follow through the loops by hand, I reach 55 on the 6th (or 7th, not sure if I'm counting correctly) loop, but it doesn't terminate and return the value for cur until pass number 11.I'm clearly not following it through correctly on paper; can anyone break this down so I can see where I'm going wrong?
Thanks so much for the help!