Lisp Discussion of DO Argument Variables

At Peter Zeibel's Practical General Lisp, he gives this example:

(do ((nums nil) (i 1 (1+ i))) ((> i 10) (nreverse nums)) (push i nums)) 

I see how this works, using nums inside the loop, but not providing it with a step form. Why would you put nums in a variable definition and not this:

 (let (nums) (do ((i 1 (+ i 1))) ((> i 10) (nreverse nums)) (push i nums))) 

I am sure that there is a good reason, but I still do not understand.

+6
syntax let lisp do-loops
source share
1 answer

Because it is convenient and saves indentation. In addition, the battery conceptually belongs to the cycle, so why not put it there?

+12
source share

All Articles