# 12.5 定义全局变量

定义变量是一种声明，声明你将如何将某个符号作为全局变量使用。特殊形式 defvar 和 defconst 即用来定义变量。

变量定义有三个目的。其一，它告知后来阅读代码的程序员，某个符号被当作变量，以某种特定的目的来使用；其二，它告知 Lisp 这个变量，同时可以为这个变量提供初始值和帮助文档；其三。它会为其他的一些辅助编程工具，比如 etags 等，提供这个变量的定义位置等信息。

使用 defvar 还是 defconst 取决于你的目的。这两个特殊式的目的时告诉程序员这个变量的值应该是可变的还是不可变的。Emacs Lisp 实际上并不会阻止你修改由 defconst 定义的变量。另外一个重要区别是，defconst 无条件的初始化定义的变量，而 defvar 仅在该变量原本是无效变量的情况下初始化。

如果你想要自定义一个变量，那么你应该使用 defcustom 。（它使用 defvar 作为子例程）

TODO


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emacs-lisp.ivory.cafe/bian-liang/ding-yi-bian-liang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
