Trying Ron Garret's utilities.lisp in ACL 8.0, I encountered macros
that expand into (SETF (APPLY ...) ...) which doesn't always work.
Is this legal CL? I think I would have written define-synonyms using
,@ instead of APPLY. But this would have been from habit rather than
principle, so I want to understand why...
CL-USER(143): (defparameter l '(a b c d))
L
CL-USER(144): (defmacro define-synonym (s1 s2)
`(progn
(setf (symbol-function ',s1) (function ,s2))
(defun (setf ,s1) (val &rest placeargs)
(setf (apply #',s2 placeargs) val))))
DEFINE-SYNONYM
CL-USER(145): (macroexpand-1 '(define-synonym fst car))
(PROGN (SETF (SYMBOL-FUNCTION 'FST) #'CAR)
(DEFUN (SETF FST) (VAL &REST PLACEARGS)
(SETF (APPLY #'CAR PLACEARGS) VAL)))
T
CL-USER(146): (define-synonym fst car)
(SETF FST)
CL-USER(147): (fst l)
A
CL-USER(148): (setf (fst l) 'x)
Error: Apply of CAR not understood as a location for Setf.
[condition type: PROGRAM-ERROR]
Restart actions (select using :continue):
0: Return to Top Level (an "abort" restart).
1: Abort entirely from this (lisp) process.
--
Andrew Philpot
USC Information Sciences Institute
·······@isi.edu
On Feb 27, 7:25 am, Andrew Philpot <·······@isi.edu> wrote:
> Trying Ron Garret's utilities.lisp in ACL 8.0, I encountered macros
> that expand into (SETF (APPLY ...) ...) which doesn't always work.
> Is this legal CL?
Interesting question - I expected it to always be, but CLHS 5.1.2.5
states SETF of APPLY is only guaranteed to work for three standardized
functions (aref, bit and sbit) and for user-defined functions, though
implementations are free to support more. This obviously excludes
#'car.
- Willem