Go to the first, previous, next, last section, table of contents.


Defining Variables

The special forms defvar and defconst allow you to define the global variables which will be used in a program. This is entirely optional; it is highly recommended though.

Special Form: defvar variable form [doc-string]
This special form defines a global variable, the symbol variable. If the value of variable is void the form is evaluated and its value is stored as the value of variable (note that the default value is modified, never a buffer-local value).

If the doc-string argument is defined it is a string documenting variable. This string is then stored as the symbol's variable-documentation property and can be accessed by the describe-variable function.

(defvar my-variable '(x y)
  "This variable is an example showing the usage of the defvar
special form.")
    => my-variable

Special Form: defconst constant form [doc-string]
defconst defines a constant, the symbol constant. Its value (in the case of a buffer-local symbol, its default value) is set to the result of evaluating form. Note that unlike defvar the value of the symbol is always set, even if it already has a value.

The doc-string argument, if defined, is the documentation string for the constant.

(defconst the-answer 42
  "An example constant.")
    => the-answer

See section Constant Variables.


Go to the first, previous, next, last section, table of contents.