title: How to simulate collecting in nested loop for
body: <p>I want to create a list of pairs <code>(a . b)</code> with <code>1 &lt; a &lt; b &lt;= n</code> up to <code>n</code>, e.g. <code>n = 5</code>:</p>
  <pre><code>((2 . 3) (2 . 4) (3 . 4) (2 . 5) (3 . 5) (4 . 5))
  </code></pre>
  <p><em>(The order of the pairs is not critical.)</em></p>
  <p>I came up with the code</p>
  <pre><code>(defun create-pairs (upper-bound)
    (loop for i from 3 to upper-bound
          for j from 2 to (1- upper-bound)
            collecting (cons j i)))
  </code></pre>
  <p>but that doesn't do what I wanted</p>
  <pre><code>* (create-pairs 5)
  ((2 . 3) (3 . 4) (4 . 5))
  </code></pre>
  <p>since the loops are incrementing at the same time.</p>
  <p>Therefore I tried this</p>
  <pre><code>(defun create-pairs (upper-bound)
    (loop for i from 3 to upper-bound do
      (loop for j from 2 to (1- upper-bound)
        collecting (cons j i))))
  </code></pre>
  <p>with the result:</p>
  <pre><code>* (create-pairs 5)
  
  NIL
  </code></pre>
  <p>I don't remember where but I read that it's not possible to use <code>collecting</code> in constructs like my second try.</p>
  <p>So how do I get the result I want to have? Isn't it possible to solve this with <code>loop for</code>?</p>