Bil*_*osa 4 lisp clisp common-lisp
我盯着斯蒂尔的Common Lisp the Language,直到我脸色苍白,仍然有这个问题.如果我编译:
(defun x ()
(labels ((y ()))
5))
(princ (x))
(terpri)
Run Code Online (Sandbox Code Playgroud)
有时候是这样的:
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$
Run Code Online (Sandbox Code Playgroud)
很公平.那么我如何要求编译器忽略函数y?我试过这个:
(defun x ()
(labels (#+ignore(y ()))
5))
(princ (x))
(terpri)
Run Code Online (Sandbox Code Playgroud)
它工作:
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$
Run Code Online (Sandbox Code Playgroud)
但不知何故,我不认为这是警告暗示我做的事情.
我该怎么办?
GNU CLISP要求你declare
的函数被ignore
剐.
(defun x ()
(labels ((y ()))
(declare (ignore (function y)))
5))
Run Code Online (Sandbox Code Playgroud)
或者(特别是如果这是宏扩展的结果,它取决于用户是否y
实际使用),
(defun x ()
(labels ((y ()))
(declare (ignorable (function y)))
5))
Run Code Online (Sandbox Code Playgroud)
(无论您希望写什么(function y)
,您都可以自由地使用读者缩写#'y
.)