[pro] Defined but no used variable warning during setf expansion

Martin Simmons martin at lispworks.com
Tue Jan 24 18:51:49 UTC 2012


>>>>> On Tue, 24 Jan 2012 07:04:43 +0100, Pascal J Bourguignon said:
> 
> Burton Samograd <burton.samograd at gmail.com> writes:
> 
> > CL-USER> (setf $x 10)
> > ; in: SETF (#:G1129 X)
> > ;     (LET* ((#:G1175 X))
> > ;       (MULTIPLE-VALUE-BIND (#:G1176)
> > ;           10
> > ;         (LET ((#:G1177 #))
> > ;           (WHEN #:G1177 (FUNCALL #:G1177 # #:G1176))
> > ;           (SETF X #:G1176))))
> > ;
> > ; caught STYLE-WARNING:
> > ;   The variable #:G1175 is defined but never used.
> 
> 
> I don't think it's a compiler error (there's no reason to treat
> uninterned symbols differently from interned ones).
> 
> 
> Clearly, there's a single occurence of #:G1175, in the binding of the
> LET* form, and no use of it.  You should either avoid generating it, or
> add a
> 
>     (declare (ignorable #:G1175)) 
> 
> expression before the body of the LET*.

Unfortunately neither of those solutions are possible directly, because the
binding is generated by the SETF macro.

The binding is there because the reader macro expansion passes X as an
argument, as in (#:G1129 X).  The setf expander is defined using DEFSETF, so
it has to evaluate all of its arguments in left-to-right order by binding them
to temporary variables.

It isn't clear to me why this argument is needed, because the DEFSETF form can
access the variable directly.

OTOH, the uses of EVAL look strange and I suspect the whole thing could be
written more clearly without needing a separate DEFMACRO and DEFSETF for each
DEFACTIVE form.  That approach would need to use DEFINE-SETF-EXPANDER instead
of DEFSETF.

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/




More information about the pro mailing list