宣告,宣告,宣告 [英] Proclaim, declaim, declare
问题描述
能否请您说明以下三个符号之间的区别:声明
,声明>
和声明
?
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.
> code> declaim 命名为 宏 ,用于制作 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.
尽管执行了
声明
的形式可能会导致
影响编译,编译器不会尝试
识别并特别处理声明形式。诸如
之类的声明(即使是顶级表单)在执行前不会对
产生任何影响:
Although the execution of a
proclaim
form has effects that might affect compilation, the compiler does not make any attempt to recognize and specially process proclaim forms. A proclamation such as the following, even if a top level form, does not have any effect until it is executed:
(声明'(特殊* x *))
如果需要编译时的副作用,则
eval-何时
可能有用。例如:
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甚至 proclaim
:首先,从历史上看,它是在 declaim
,其次是 proclaim
在宏中更简单,更有用。
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.
这篇关于宣告,宣告,宣告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!