[Ecls-list] Patch: macro expansion when expanding a setf form

Josh Elsasser josh at elsasser.org
Sat Aug 30 20:53:52 UTC 2008


when attempting to macroexpand a form to find a setf expansion,
MACROEXPAND is used instead of MACROEXPAND-1.  This means that the
setf expansion will not be found for a macro which expands into a
SETFable place which is also happens to be a macro.

For example, given the following pseudo-definitions:

(defmacro inner ...)
(define-setf-expander inner ...)
(defmacro outer (val)
  `(inner ,val))

The setf expansion defined for inner will not be found for a form like
(setf (outer foo) bar)

A patch to incrementally expand macros with MACROEXPAND-1 follows:

--- src/lsp/setf.lsp
+++ src/lsp/setf.lsp
@@ -111,7 +111,7 @@ Does not check if the third gang is a single-element list."
 	     (push item all-args))
 	   (values (gensym) (nreverse names) (nreverse values) (nreverse all-args))))
     (cond ((symbolp form)
-	   (if (and (setq f (macroexpand form env)) (not (equal f form)))
+	   (if (and (setq f (macroexpand-1 form env)) (not (equal f form)))
 	       (get-setf-expansion f env)
 	       (let ((store (gensym)))
 		 (values nil nil (list store) `(setq ,form ,store) form))))
@@ -130,7 +130,7 @@ Does not check if the third gang is a single-element list."
 			    (setf-structure-access (car all) (car f) (cdr f) store))
 			   ((setq f (get-sysprop (car form) 'SETF-LAMBDA))
 			    (apply f store all))
-			   ((and (setq f (macroexpand form env)) (not (equal f form)))
+			   ((and (setq f (macroexpand-1 form env)) (not (equal f form)))
 			    (return-from get-setf-expansion
 			      (get-setf-expansion f env)))
 			   (t




More information about the ecl-devel mailing list