我如何要求Lisp编译器忽略(标签种类)函数?

时间:2012-02-26 21:00:48

标签: lisp common-lisp clisp

我盯着斯蒂尔的 Common Lisp the Language ,直到我脸红了,仍然有这个问题。如果我编译:

(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$ 

但不知怎的,我不认为这是警告暗示我的意思。

我该怎么办?

1 个答案:

答案 0 :(得分:8)

GNU CLISP要求您将declare函数设为ignored

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

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

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

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