Page 1 of 1

Re: DEFSTRUCT POINT

Posted: Tue Jan 31, 2012 11:46 pm
by nuntius
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))

Re: DEFSTRUCT POINT

Posted: Sat Jun 09, 2012 5:03 am
by edgar-rft
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.