如何要求Lisp编译器忽略(标签变体)函数?
我一直盯着斯蒂尔的公共口齿不清语言,直到我脸色发青,仍然有这个问题。如果我编译:如何要求Lisp编译器忽略(标签变体)函数?,lisp,common-lisp,clisp,Lisp,Common Lisp,Clisp,我一直盯着斯蒂尔的公共口齿不清语言,直到我脸色发青,仍然有这个问题。如果我编译: (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
(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正在要求您使用该函数 或者(特别是如果这是宏扩展的结果,取决于用户是否实际使用了
y
)
(无论您在哪里编写
(函数y)
,您都可以自由使用读取器缩写#y
。仅供参考,#+ignore
允许读取器跳过整个下一个表单(当然,除非*功能*
中有ignore
)。那是我的邪恶计划。但下面的答案中概述的好计划占了上风。:)CLtl和CLtl2都是过时的书籍,只推荐给对lisp历史感兴趣的人,而不是用作参考或学习材料。对于现代ANSI通用lisp阅读,我推荐Peter Seibel的实用通用lisp和Conrad Barski的lisp之地。
(defun x ()
(labels ((y ()))
(declare (ignore (function y)))
5))
(defun x ()
(labels ((y ()))
(declare (ignorable (function y)))
5))