[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SETF of APPLY
I agree with your proposed revised description of SETF of APPLY. The specific
code in our implementation of APPLY's SETF-method follows; it may be useful
in constructing the English description. This is not the whole SETF-method,
just the relevant code fragment.
(DEFINE-SETF-METHOD APPLY (FUNCTION &REST ARGS)
(SETQ FUNCTION (SECOND FUNCTION))
(MULTIPLE-VALUE-BIND (VARS VALS STORE-VARS STORE-FORM ACCESS-FORM)
(GET-SETF-METHOD-MULTIPLE-VALUE (CONS FUNCTION ARGS))
(LET ((LIST-VAR (LOOP FOR VAR IN VARS AND VAL IN VALS
WHEN (EQ VAL (CAR (LAST ARGS))) RETURN VAR)))
(OR (AND LIST-VAR
(EQ (CAR (LAST ACCESS-FORM)) LIST-VAR)
(EQ (CAR (LAST STORE-FORM)) LIST-VAR))
(ERROR "APPLY of ~S not understood as a generalized variable" FUNCTION))
While SETF of APPLY of AREF could be implemented some other way, not involving
the last argument to the original form remaining last in the access-form and
store-form, I think it is necessary for SETF of APPLY of a user-defined function
to work this way.
This is all certainly ugly, but I still think the alternative (a separate
DEFSETF system for functions seen inside APPLY) would be a lot worse.