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

Spurious unused lexical var



 >Date: 12 Nov 1993 10:08:10 -0600
 >From: "Don Mitchell" <dhm%proact@uunet.UU.NET>
 >Subject: Spurious unused lexical var
 >To: "Info-mcl" <info-mcl@cambridge.apple.com>
 >
 >Subject:   Spurious unused lexical variable compiler warning?
 >Why does the compiler say
 >
 >;Compiler warnings :
 >;   Unused lexical variable QUERY?, in EXAMPLE.
 >EXAMPLE
 >
 >when compiling (the obviously contrived for mass-distribution)
 >
 >(defun example (n-list)
 >  (loop with query? and known? and result
 >        for n in n-list
 >        if (multiple-value-setq  (query? known?)
 >               (subtypep n 'number))
 >        return result
 >        else do (if known? (push n result))))
 >
 >The if statement is using the first value of the multiple-value-setq.  How
 >else can we capture the first value other than using a variable?  Wouldn't
 >(declare (ignore query?)) be misleading?

You might want to try something like this instead. It's a matter of style,
and is definitely "lisp style" (as opposed to C/Pascal/Fortran style)... but
if you're using setq/setf, you should usually ask yourself if maybe you should 
see if you can use let/multiple-value-bind instead:


(defun example (n-list)
    (loop with result
          for n in n-list
          do (multiple-value-bind (query? known?)
                                  (subtypep n 'number)
               (if query?
                 (return result)
                 (if known? (push n result))))))