禁止对 LISP 中未使用的函数参数发出警告 [英] Suppress warning for function arguments not used in LISP

查看:31
本文介绍了禁止对 LISP 中未使用的函数参数发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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?

推荐答案

查看 Common Lisp Hyperspec:声明忽略,可忽略

See the Common Lisp Hyperspec: Declaration IGNORE, IGNORABLE

未使用变量.忽略它.

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

上面告诉编译器 y 不会被使用.

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.

可能未使用变量.不在乎.

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

以上告诉编译器可能不会使用y.

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.

这篇关于禁止对 LISP 中未使用的函数参数发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆