问题描述
能否请您说明以下三个符号之间的区别:声明
,声明>
和声明
?
Can you please explain the differences between the three symbols proclaim
, declaim
and declare
?
推荐答案
它们是,而不是。
-
命名为用于使全局 。您应该使用
proclaim
names a function for making global declarations. You should usedeclaim
instead whenever possible.
命名为,用于制作 global (例如 ),它们在编译时也有效。
declaim
names a macro for making global declarations (like proclaim
) which are also effective at compile-time.
只是(即,它没有命名,,或者),以便在其中进行 some 形式的开始(您可以将其视为这些形式的语法的元素)。
declare
is just a symbol (i.e., it does not name a function, macro, or special operator) for making local declarations in the beginning of some forms (you can view it as an element of syntax of those forms).
因此,前两个会影响,最后一个是。
So, the first two affect the global environment and the last one is local.
比,因为它在:
(声明'(特殊* x *))
如果需要编译时的副作用,则
可能有用。例如:
If compile time side effects are desired, eval-when
may be useful. For example:
(eval-when(:execute:compile-toplevel:load-toplevel)
(proclaim'(special * x *)))
但是,在大多数情况下,最好使用
。
In most such cases, however, it is preferrable to use declaim
for this purpose.
即,如果您的代码是
(proclaim '(special *x*))
(defun foo () (print *x*))
编译器会抱怨 foo
读取未知的特殊变量 * x *
,而
the compiler will complain that foo
reads an unknown special variable *x*
, while
(declaim (special *x*))
(defun foo () (print *x*))
不会引起警告。
PS 。如果您想知道为什么CL甚至:首先,从历史上看,它是在,其次是在宏中更简单,更有用。
PS. If you are wondering why CL even has proclaim
: first, historically it was there before declaim
, and, second, proclaim
is simpler and more useful in macros.
这篇关于宣告,宣告,宣告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!