Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warning for function arguments not used in LISP

In lisp, I need to define a set of functions, all with the same number of arguments. However, the functions may or may not use all the arguments, leading to a spur of warning messages. For example:

(defun true (X Y) X)
[...]
; caught STYLE-WARNING:
;   The variable Y is defined but never used.

Is there a way to warn the compiler that is was intended?

like image 849
PierreBdR Avatar asked Mar 06 '14 17:03

PierreBdR


1 Answers

See the Common Lisp Hyperspec: Declaration IGNORE, IGNORABLE

A variable is not used. Ignore it.

(defun true (x y)
  (declare (ignore y))
  x)

Above tells the compiler that y is not going to be used.

The compiler will complain if it is used. It will not complain if it is not used.

A variable might not be used. Don't care.

(defun true (x y)
  (declare (ignorable y))
  x)

Above tells the compiler that y might not be used.

The compiler will not complain if it is used and also not if it is not used.

like image 98
Rainer Joswig Avatar answered Sep 22 '22 00:09

Rainer Joswig