The sortf function from Chapter 12 of the book "On Lisp" originally used get-setf-method, which is currently unavailable in a recent SBCL by default.
Therefore, get-setf-expansion was used instead of get-setf-method in a modified version of sortf.
However, the modified sortf does not work, because get-setf-expansion returns the same symbol with the fixed name #:NEW1 rather than a symbol created from gensym.
The problem of the same symbol name results in different macro expansions between two versions of sortf.
For example, when executing
(macroexpand-1 '(sortf > x (aref ar (incf i)) (car lst)))
the output from the original sortf is
;; Extracted from "On Lisp":
;; https://github.com/showgood/onlisp/blob/fc91b63b1854afb2596d4f27b3e87202214c01c8/onlisp.org?plain=1#L9046
(let* ((#:g1 x)
(#:g4 ar)
(#:g3 (incf i))
(#:g2 (aref #:g4 #:g3))
(#:g6 lst)
(#:g5 (car #:g6)))
(unless (> #:g1 #:g2)
(rotatef #:g1 #:g2))
(unless (> #:g1 #:g5)
(rotatef #:g1 #:g5))
(unless (> #:g2 #:g5)
(rotatef #:g2 #:g5))
(setq x #:g1)
(system:set-aref #:g2 #:g4 #:g3)
(system:set-car #:g6 #:g5))
and the output from the modified sortf is
;; Executed with "SBCL 2.1.11.debian"
(LET* ((#:NEW1 X)
(#:AR636 AR)
(#:G637 (INCF I))
(#:NEW1 (AREF #:AR636 #:G637))
(#:LST638 LST)
(#:NEW1 (CAR #:LST638)))
(UNLESS (> #:NEW1 #:NEW1) (ROTATEF #:NEW1 #:NEW1))
(UNLESS (> #:NEW1 #:NEW1) (ROTATEF #:NEW1 #:NEW1))
(UNLESS (> #:NEW1 #:NEW1) (ROTATEF #:NEW1 #:NEW1))
(SETQ X #:NEW1)
(FUNCALL #'(SETF AREF) #:NEW1 #:AR636 #:G637)
(SB-KERNEL:%RPLACA #:LST638 #:NEW1))
where the symbol #:NEW1 is repeatedly used.
I'm wondering if there is a better replacement for get-setf-method than get-setf-expansion.
UPDATE
I have tested the sortf that uses get-setf-expansion again, and it works well in most cases, although the result of macroexpand-1 is weird.
One exceptional case is
(let ((i 0)
(x 10)
(ar #(10 20 30))
(lst '(25 30 35)) ; This raise error
;; (lst (list 25 30 35)) ; This make code works
)
(sortf > x (aref ar (incf i)) (car lst))
(list x (aref ar 1) (car lst)))
whose output is (25 20 25) rather than (25 20 10).
I think it's not a problem from get-setf-expansion.
Summary of Replies
The #:NEW1 symbols that are generated by get-setf-expansion are different uninterned symbols. Therefore, get-setf-method can be replaced with get-setf-expansion in a macro such as sortf, and the modified macro will work in the same way. To distinguish uninterned symbols of the same name, cl:*print-circle* can be set as t.
In addition, modifying a literal, such as '(25 30 35), with an operation like setf can results in weird output. In particular, the result of modifying a literal can vary depending on the level of compiler optimization of SBCL. In another compiler, modifying a literal can raise compile or runtime error.