title: How to make a list of pairs in lisp?
body: <p>I'm trying to do a list of pairs as a part of a homework assignment.</p>
  
  <p>I tried doing (somewhere in the middle of a function)</p>
  
  <pre><code>(setq list1 (append list1 (cons n1 n2)))
  </code></pre>
  
  <p>And for some reason I don't understand, this works fine with the first pair, but as I try to append the second pair, this error pops up:</p>
  
  <blockquote>
    <p>*** - APPEND: A proper list must not end with 2</p>
  </blockquote>
  
  <p>How can I solve this?</p>
  
  <p>So, continuing on this subject, thanks to the answer given, I was able to correct my problem. But a new one came up, and I think it is related with it. So, I have this function:</p>
  
  <pre><code>(defun action(state)
  (let ((list_actions '())
        (limNumActions (1- (list-length state)))
        (limNumSubActions 0)
        (numActions 0)
        (numSubActions 0))
    (loop for numActions from 0 to limNumActions do
      (setq limNumSubActions (1- (list-length (nth numActions state))))
      (loop for numSubActions from 0 to limNumSubActions do
        (setq list_actions (append list_actions
          (list (cons numActions numSubActions))))
        (print 'list_actions)
        (print list_actions)))))
  </code></pre>
  
  <p>I used the <code>print</code>function as a simple "debugger". It returns this:</p>
  
  <pre><code> LIST_ACTIONS 
   ((0 . 0)) 
   LIST_ACTIONS 
   ((0 . 0) (0 . 1)) 
   LIST_ACTIONS 
   ((0 . 0) (0 . 1) (1 . 0)) 
   LIST_ACTIONS 
   ((0 . 0) (0 . 1) (1 . 0) (1 . 1)) 
   NIL
  </code></pre>
  
  <p>And this is exactly the result I was expecting! Except for the <code>NIL</code> part... Can you understand why the list <code>list_actions</code> is <code>NIL</code>at the end?</p>