title: Swap Elements in Lisp list
body: <p>I'm trying to implement a function that returns a list of LIST (each list in LIST is the result of two elements swapped in list). It's supposed to do a search based on the list formed from each swap. It is part of my program to solve the 8 puzzle problem. Here's what i have so far</p>
  
  <pre><code>(setq *LIST* nil) 
  
  (defun swapped_list(lst)
   (loop for j in (positions_to_swap) do
      (setq *LIST* (rotatef (nth pos lst) (nth j lst))
        *LIST*)
  
  (swapped_list '(11 12 13 14 15 16 17 18 19))
  </code></pre>
  
  <p>If <code>positions_to_swap</code> is <code>(0 2 5)</code> and <code>pos</code> is <code>4</code>, this should return
  <code>((15 12 13 14 11 16 17 18 19) (11 12 15 14 13 16 17 18 19) (11 12 13 14 16 15 17 18 19))</code></p>
  
  <p>I've been spending countless hours trying to debug with no progress. I've tried many variants but none of them work.</p>