(defun keepfirst (n list &optional (res nil))
(cond ((or (= n 0) (null list))(reverse res))
(t (keepfirst (- n 1) (rest list) (cons (first list) res)))
)
)
(defun inbetween (pos1 pos2 list)
(keepfirst (- pos2 (1+ pos1)) (nthcdr (1+ pos1) list))
)
(defun swap (pos1 pos2 list)
(append (keepfirst pos1 list)
(list (nth pos2 list))
(inbetween pos1 pos2 list)
(list (nth pos1 list))
(nthcdr (1+ pos2) list))
)
;; (load "swap")
;; (setf mylist '(a b c d e f))
;; (swap 0 3 mylist)
;; (D B C A E F)
;; (swap 2 3 mylist)
;; (A B D C E F)
;; (swap 0 2 mylist)
;; (C B A D E F)
;; (swap 0 1 mylist)
;; (B A C D E F)
syntax highlighted by Code2HTML, v. 0.9.1