SBCL warns that a variable is defined but never used

I get a warning from the sbcl compiler that the variable is defined but not used. And the compiler is right. I want to get rid of the warning, but I don’t know how to do it. Here is an example:

(defun worker-1 (context p) ;; check context (make use of context argument) (if context (print p))) (defun worker-2 (context p) ;; don't care about context ;; will throw a warning about unused argument (print p)) ;; ;; calls a given worker with context and p ;; doesn't know which arguments will be used by the ;; implementation of the called worker (defun do-cmd (workerFn context p) (funcall workerFn context p)) (defun main () (let ((context ())) (do-cmd #'worker-1 context "A") (do-cmd #'worker-2 context "A"))) 

The do-cmd function expects worker workers implementing a specific interface f (context p).

The sbcl compiler generates the following warning:

 in: DEFUN WORKER-2 ; (DEFUN WORKER-2 (CONTEXT P) (PRINT P)) ; ; caught STYLE-WARNING: ; The variable CONTEXT is defined but never used. ; ; compilation unit finished ; caught 1 STYLE-WARNING condition 
+6
source share
1 answer

You need to declare that the parameter is intentionally ignored .

 (defun worker-2 (context p) (declare (ignore context)) (print p)) 

( ignore also issues a warning if you use this variable. To suppress warnings in both cases, you can use the ignorable , but this should only be used in macros and in cases where it is impossible to determine whether the variable will be used at the point of its declaration .)

+11
source

All Articles