我盯着斯蒂尔的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$
但不知何故,我不认为警告暗示我应该这样做。
我该怎么办?
GNU CLISP 要求您declare http://www.lispworks.com/documentation/HyperSpec/Body/s_declar.htm函数为ignored http://www.lispworks.com/documentation/HyperSpec/Body/d_ignore.htm#ignore.
(defun x ()
(labels ((y ()))
(declare (ignore (function y)))
5))
或者(特别是如果这是宏扩展的结果,则取决于用户是否y
实际使用与否),
(defun x ()
(labels ((y ()))
(declare (ignorable (function y)))
5))
(无论您希望在哪里写(function y)
,您可以自由使用读者缩写#'y
反而。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)