6

In Peter Seibel's Practical Common Lisp, he gives this example:

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

I can see how it works, using nums inside the loop but not giving it a step-form. Why would you put nums in the variable-definition rather than do this:

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

I'm sure there's a good reason, but I don't get it yet.

1 Answer 1

12

Because it's convenient and saves indentation. Furthermore, the accumulator conceptually belongs to the loop, so why not put it there?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.