DEFSTRUCT POINT

Discussion of Emacs Lisp
Post Reply
nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: DEFSTRUCT POINT

Post by nuntius » Tue Jan 31, 2012 11:46 pm

The following will work in CL and I believe elisp.

Code: Select all

(psetf (point-x p) (point-y p)
       (point-y p) (point-x p))
If not, you may need to use an explicit temporary variable. Something like

Code: Select all

(let ((x (point-x p)))
  (setf (point-x p) (point-y p)
        (point-y p) x))

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: DEFSTRUCT POINT

Post by edgar-rft » Sat Jun 09, 2012 5:03 am

A very old trick to swap values is:

Code: Select all

(defmacro swap (place1 place2)
  `(setf ,place1 (prog1 ,place2 (setf ,place2 ,place1))))
Or with points:

Code: Select all

(setf (point-x p) (prog1 (point-y p) (setf (point-y p) (point-x p))))
This has the same effect as PSETF, and needs no explicit temporary variable.

Post Reply