问题描述
我一直盯着斯蒂尔(Steele)的 Lisp语言常用语,直到我脸色发青为止,仍然有这个问题.如果我编译:
I've stared at Steele's Common Lisp the Language until I'm blue in the face, and still have this question. If I compile:
(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?我试过了:
Fair enough. So how do I ask the compiler to ignore function y? I tried this:
(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$
但是以某种方式我不认为这是警告提示我这样做的原因.
but somehow I don't think that's what the warning is suggesting that I do.
我该怎么办?
推荐答案
GNU CLISP is asking you to declare
the function to be ignore
d.
(defun x ()
(labels ((y ()))
(declare (ignore (function y)))
5))
或者(特别是如果这是宏扩展的结果,而宏扩展取决于用户是否实际使用y
),
Alternatively (especially if this is the result of a macro expansion where it depends on the user whether y
is actually used or not),
(defun x ()
(labels ((y ()))
(declare (ignorable (function y)))
5))
(只要您希望写(function y)
,就可以随意使用阅读器缩写#'y
.)
(Wherever you are expected to write (function y)
, you are free to use the reader abbreviation #'y
instead.)
这篇关于我如何要求Lisp编译器忽略(label-variety)函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!