ignore, ignorable
ignore, ignorable Declaration
Syntax:
(ignore {var | (function fn)}*)
(ignorable {var | (function fn)}*)
Arguments:
var—a variable name.
fn—a function name.
Valid Context:
declarationBinding Types Aected:
variable, function
Description:
The ignore and ignorable declarations refer to for-value references to variable bindings for the vars and to function bindings for the fns.
An ignore declaration specifies that for-value references to the indicated bindings will not occur within the scope of the declaration. Within the scope of such a declaration, it is desirable for a compiler to issue a warning about the presence of either a for-value reference to any var or fn, or a special declaration for any var.
An ignorable declaration specifies that for-value references to the indicated bindings might or might not occur within the scope of the declaration. Within the scope of such a declaration, it is not desirable for a compiler to issue a warning about the presence or absence of either a for-value reference to any var or fn, or a special declaration for any var.
When not within the scope of a ignore or ignorable declaration, it is desirable for a compiler to issue a warning about any var for which there is neither a for-value reference nor a special declaration, or about any fn for which there is no for-value reference.
Any warning about a “used” or “unused” binding must be of type style-warning, and may not a↵ect program semantics.
The stream variables established by with-open-file, with-open-stream, with-input-from-string, and with-output-to-string, and all iteration variables are, by definition, always “used”. Using (declare (ignore v)), for such a variable v has unspecified consequences.
See Also:
declareExpanded Reference: ignore, ignorable
A key point to declaring variable bindings to be ignored is that the declaration must be within the scope where the binding happens.
Here are a few examples of using this declaration:
let
Example
(let ((x 24)) (declare (ignorable x)))
Notice how the declaration is after the x
is bound. See also the syntax for let where the declaration is explicitly specified after the bindings and before the forms.
Without an ignore declararation we get the expected compiler warning:
CL-USER> (let ((x 24)))
; in: LET ((X 24))
; (X 24)
;
; caught STYLE-WARNING:
; The variable X is defined but never used.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
NIL
defun
Example
CL-USER> (defun foo (x) (declare (ignore x)) (format T "Hello World!"))
Notice again that the declaration is after the x
is bound.
CL-USER> (foo 24)
Hello World!NIL
And there is no compiler warning about x
not being used.
However without the ignore declaration a compiler warning is issued:
CL-USER> (defun foo (x) (format T "Hello World!"))
; in: DEFUN FOO
; (SB-INT:NAMED-LAMBDA FOO
; (X)
; (BLOCK FOO (FORMAT T "Hello World!")))
;
; caught STYLE-WARNING:
; The variable X is defined but never used.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
WARNING: redefining COMMON-LISP-USER::FOO in DEFUN
FOO
Other Examples
TODO: Please contribute to this page by adding explanations and examples
(ignore, ignorable )