4

我一直盯着斯蒂尔的Common Lisp 语言,直到我脸色发青,仍然有这个问题。如果我编译:

(defun x ()
  (labels ((y ()))
    5))
(princ (x))
(terpri)

有时候是这样的:

home:~/clisp/experiments$ clisp -c -q x.lisp
;; Compiling file /u/home/clisp/experiments/x.lisp ...
WARNING in lines 1..3 :
function X-Y is not used.
Misspelled or missing IGNORE declaration?
;; Wrote file /u/home/clisp/experiments/x.fas
0 errors, 1 warning
home:~/clisp/experiments$ 

很公平。那么如何让编译器忽略函数 y?我试过这个:

(defun x ()
  (labels (#+ignore(y ()))
    5))
(princ (x))
(terpri)

它奏效了:

home:~/clisp/experiments$ clisp -c -q y.lisp
;; Compiling file /u/home/clisp/experiments/y.lisp ...
;; Wrote file /u/home/clisp/experiments/y.fas
0 errors, 0 warnings
home:~/clisp/experiments$ 

但不知何故,我认为这不是警告所暗示的。

我该怎么办?

4

1 回答 1

9

GNU CLISP 要求您使用ddeclare的功能。ignore

(defun x ()
  (labels ((y ()))
    (declare (ignore (function y)))
    5))

或者(特别是如果这是宏扩展的结果,这取决于用户是否y实际使用),

(defun x ()
  (labels ((y ()))
    (declare (ignorable (function y)))
    5))

(无论您希望在哪里写(function y),您都可以随意使用读者缩写#'y。)

于 2012-02-26T21:17:34.040 回答