Skip to content

Instantly share code, notes, and snippets.

@xuchunyang
Created September 7, 2015 07:40
Show Gist options
  • Save xuchunyang/abee057c0dddc5bccd0d to your computer and use it in GitHub Desktop.
Save xuchunyang/abee057c0dddc5bccd0d to your computer and use it in GitHub Desktop.
Swap values of variables and Swap car and cdr of cons cell in Emacs Lisp
(let ((a 1) (b 2))
(setq a (prog1 b (setq b a)))
(list a b))
;; => (2 1)
(let ((con '(1 . 2)))
(setcar con (prog1 (cdr con)
(setcdr con (car con))))
con)
;; => (2 . 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment