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

A question about ignoring IGNORE



    Date: Wed, 18 Nov 87 11:17 EST
    From: Jeffrey Mark Siskind <Qobi@ZERMATT.LCS.MIT.EDU>

    If I have a macro which expands into some lisp code which contains
    local variable definitions (either through LET or DEFUN etc.)
    and I don't know or care whether all such variables will be used
    by any particular expansion of the macro, I run into the
    following annoying problem. The compiler will complain and issue
    warnings that the variables are unused, but if I declare them
    as (DECLARE (IGNORE FOO)) and the variables are unused then
    the compiler will complain and issue a warning that the variables
    are used. It turns out to be to much of a pain for me to
    determine whether a given variable is used and conditionally
    include its binding in the expanded output of the macro. So
    as the old saying goes, how do I avoid being "Damned if you
    do, and damned if you don't"? What I really want is something
    like (DECLARE (I-DONT-CARE-IF-IT-IS-UNUSED FOO)).

Do something like the following:

(defmacro foo (&body body &environment env)
  ;; generate your let-pairs and vars
  (multiple-value-bind (declarations real-body)
      (sys:find-body-declarations body env)
    `(let (,@let-pairs)
       ,@declarations
       ,@vars					;ignore them all
       ,@real-body)))

Of course just including all the vars in the body works to ignore them,
and the compiler optimizes out the references to them.  The use of the
sys:find-body-declarations is in case the body arg to the macro has any
declarations -- you would want them to appear in the right place.

Hope this helps.