This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

DEFSTRUCT POINT

2 posts · 6650 views

Re: DEFSTRUCT POINT

The following will work in CL and I believe elisp.
(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
(let ((x (point-x p)))
  (setf (point-x p) (point-y p)
        (point-y p) x))

Re: DEFSTRUCT POINT

A very old trick to swap values is:
(defmacro swap (place1 place2)
  `(setf ,place1 (prog1 ,place2 (setf ,place2 ,place1))))
Or with points:
(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.