[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SETF of APPLY



Hedrick is quite correct that there is a glaring inconsistency
in what the manual says about SETF of APPLY.  I think that what it
says ought to be approximately the truth, but it needs to be hedged
with something about the need to use LET to get the evaluation order
straight.  It is of course precisely to avoid such messy details
that SETF is a canned primitive in the first place.

What would you think of the more complex strategy outlined below
as a replacement for some of the text on page 96?



The SETF method for the function <name> must be such that the
expansion of

(SETF (<name> <z1> <z2> ... <zn> <zrest>) <z0>)

uses the form <zrest> (or the generated variable that fronts for it)
only as the last argument in some number of function calls

(<any-function> <q1> ... <qn> <zrest>)

Every such function call in the expansion is altered to be

(APPLY #'<any-function> <q1> ... <qn> <zrest>)


For example, suppose that (SETF (AREF FOO (P) (Q) (R)) X) were to expand to

(LET* ((#:G0018 FOO)
       (#:G0019 (P))
       (#:G0020 (Q))
       (#:G0021 (R)))
  (ASET X #:G0018 #:G0019 #:G0020 #:G0021))

Then the expansion of (SETF (APPLY #'AREF FOO (P) (Q) (R)) X) would be

(LET* ((#:G0018 FOO)
       (#:G0019 (P))
       (#:G0020 (Q))
       (#:G0021 (R)))
  (APPLY #'ASET X #:G0018 #:G0019 #:G0020 #:G0021))

--Guy