宣告,宣告,宣告 [英] Proclaim, declaim, declare

查看:108
本文介绍了宣告,宣告,宣告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您说明以下三个符号之间的区别:声明声明> 声明

Can you please explain the differences between the three symbols proclaim, declaim and declare?

推荐答案

它们是 符号 ,而不是 关键字


  1. proclaim 命名为 功能 用于使全局 声明。您应该使用 断言

  1. proclaim names a function for making global declarations. You should use declaim 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.

声明 proclaim ,因为它在编译环境


尽管执行了 声明 的形式可能会导致
影响编译,编译器不会尝试
识别并特别处理声明形式。诸如
之类的声明(即使是顶级表单)在执行前不会对
产生任何影响:

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屋!

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