DEFSTRUCT POINT

Discussion of Emacs Lisp

Re: DEFSTRUCT POINT

Postby 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))
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: DEFSTRUCT POINT

Postby 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.
edgar-rft
 
Posts: 157
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany


Return to Emacs Lisp

Who is online

Users browsing this forum: No registered users and 2 guests