Lists and Cons Cells

(cons 1 2)                     ; (1 . 2): a dotted pair
(cons 1 '(2 3))                ; (1 2 3)
(list 1 2 3)                   ; (1 2 3)
(list* 1 2 '(3 4))             ; (1 2 3 4)
(car '(1 2 3))  (first '(1 2 3))    ; 1
(cdr '(1 2 3))  (rest '(1 2 3))     ; (2 3)
(second '(1 2 3)) (third '(1 2 3)) (tenth (loop for i from 1 to 10 collect i))
(cadr '(1 2 3))                ; 2
(nth 2 '(a b c))               ; C
(nthcdr 1 '(a b c))            ; (B C)
(last '(1 2 3))                ; (3)
(butlast '(1 2 3))             ; (1 2)
(append '(1 2) '(3) '(4 5))    ; (1 2 3 4 5)
(length '(1 2 3))              ; 3
(reverse '(1 2 3))             ; (3 2 1)
(member 2 '(1 2 3))            ; (2 3): the tail starting at the match
(null '())  (endp '())         ; T T
(listp '(1)) (consp '(1)) (atom 5)  ; T T T
(copy-list '(1 2 3))
(make-list 3 :initial-element 0)   ; (0 0 0)
(subst 'x 'b '(a b (b c)))     ; (A X (X C))
(union '(1 2) '(2 3)) (intersection '(1 2) '(2 3)) (set-difference '(1 2 3) '(2))
(adjoin 1 '(2 3))              ; (1 2 3)
(remove-duplicates '(1 2 1 3)) ; (2 1 3)
(mapcar #'+ '(1 2) '(10 20))   ; (11 22)
(mapcan (lambda (x) (if (evenp x) (list x))) '(1 2 3 4))   ; (2 4): map and splice
…

9.1 Destructive Operations

Destructive ("n" = non-consing) mapcan (already destructive on its results)

Destructive functions may reuse the argument's structure. Always use the return value ((setf list (delete x list))), and never destructively modify quoted literal lists.

(defparameter *nums* (list 3 1 2))     ; LIST creates fresh, mutable conses
(setf *nums* (sort *nums* #'<))        ; SORT is destructive: always capture the result