我如何要求Lisp编译器忽略(label-variety)函数? [英] How do I ask the Lisp compiler to ignore a (label-variety) function?

查看:89
本文介绍了我如何要求Lisp编译器忽略(label-variety)函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直盯着斯蒂尔(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要求您 declare 该功能为 d .

GNU CLISP is asking you to declare the function to be ignored.

(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)函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆