Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top