Macro: SORTF

Source

(defmacro sortf (op &rest places)
  (let* ((meths (loop for p in places
		     collect (multiple-value-list
			      (get-setf-expansion p))))
	 (temps (apply #'append (mapcar #'third meths))))
    `(let* ,(mapcar #'list
		    (mapcan (lambda (m)
			      (append (first m)
				      (third m)))
			    meths)
		    (mapcan (lambda (m)
			      (append (second m)
				      (list (fifth m))))
			    meths))
      ,@(mapcon (lambda (rest)
		  (mapcar (lambda (arg)
			    `(unless (,op ,(car rest) ,arg)
			      (rotatef ,(car rest) ,arg)))
			  (cdr rest)))
		temps)
      ,@(mapcar #'fourth meths))))
Source Context