title: Lisp macro (or function) for nested loops
body: <p>Is it possible to write a Common Lisp macro that takes a list of dimensions and variables, a body (of iteration), and creates the code consisting of as many nested loops as specified by the list?</p>
  
  <p>That is, something like:</p>
  
  <pre><code>(nested-loops '(2 5 3) '(i j k) whatever_loop_body)
  </code></pre>
  
  <p>should be expanded to</p>
  
  <pre><code>(loop for i from 0 below 2 do
    (loop for j from 0 below 5 do
      (loop for k from 0 below 3 do
        whatever_loop_body)))
  </code></pre>
  
  <p><strong>Follow up</strong></p>
  
  <p>As huaiyuan correctly pointed out, I have to know the parameters to pass to macro at compile time. If you actually need a function as I do, look below.</p>
  
  <p>If you are ok with a macro, go for the recursive solution of 6502, is wonderful.</p>