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

Screw with DEFVST (which otherwise works fine)



(DEFVST GRUNT FOO BAR BAZ)

(DEFMACRO CLOBBER (FROB)
	  (COND ((EQ (CAR FROB) 'CAR)
		 `(RPLACA ,(CADR FROB) (CLOBBERIFIER ,FROB)))
		((EQ (CAR FROB) 'CDR)
		 `(RPLACD ,(CADR FROB) (CLOBBERIFIER ,FROB)))
		(T `(SETF ,FROB (CLOBBERIFIER ,FROB)))))

(CLOBBER (GRUNT-BAR MY-FAVORITE-GRUNT))

This fails to work because the two occurrences of FROB (i.e. of
(GRUNT-BAR MY-FAVORITE-GRUNT)) in the generated SETF
form will be EQ.  The second occurrence is evaluated first,
and macro-expanded in the process.  As a result, the SETF
(i.e. SETVST) sees a form as its first argument whose car
is MACROEXPANDED rather than GRUNT-BAR, so it gets very unhappy.
I am fixing this by writing instead
		...
		(T `(SETF ,(APPEND FROB '()) (CLOBBERIFIER ,FROB)))))
but this seems to be a crock.  Is there any hope of a reasonable
general solution to this problem?