gpt4 book ai didi

lisp - 宣布,宣布,宣布

转载 作者:太空宇宙 更新时间:2023-11-03 18:32:31 25 4
gpt4 key购买 nike

能否解释一下proclaimdeclaimdeclare这三个符号的区别?

最佳答案

它们是 symbols , 不是 keywords .

  1. proclaim命名为function使全局化 declarations .你应该使用 declaim而是尽可能。

  2. declaim命名为macro使全局化 declarations (如 proclaim )在编译时也有效。

  3. declare只是一个symbol (即,它没有命名 functionmacrospecial operator )用于制作 local declarations一些形式的开头(您可以将其视为这些形式的语法的一个元素)。

因此,前两个影响 global environment最后一个是local .

declaim优于 proclaim因为它在 compilation environment 中立即生效:

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:

(proclaim '(special *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*,而

(declaim (special *x*))
(defun foo () (print *x*))

不会引起警告。

附言。如果你想知道为什么 CL 甚至有 proclaim : 首先,历史上它在那之前 declaim ,和,第二,proclaim在宏中更简单、更有用。

关于lisp - 宣布,宣布,宣布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14813801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com