Suppose I have
(setq a 1 b 2)
How can I elegantly swap the values of a
and b
without using a temporary variable?
Suppose I have
(setq a 1 b 2)
How can I elegantly swap the values of a
and b
without using a temporary variable?
This is the elegant idiom I use ;-).
(setq a (prog1 b (setq b a)))
If memory serves me well and you're willing to use cl-lib
then:
(cl-rotatef a b)
Note that this is Common Lisp way of solving the problem.
If it's integers:
(setq a (logxor a b))
(setq b (logxor a b))
(setq a (logxor a b))
:)