tags:

views:

277

answers:

3

How can I exchange two variables in LISP without using a third variable?

+4  A: 
(set! a (list a b))
(set! b (car a))
(set! a (cadr a))
eljenso
+20  A: 
(rotatef a b)
ayrnieu
A: 

Also:

(let ((a b) (b a)) ...)

khedron
That does not change the variables' values, it only creates new lexical bindings.
dmitry_vk
@dmitry-vk: That's often all you need. It depends on what you're doing, of course.
khedron