9.1 Symbol Components

Each symbol has four components (or “cells”), each of which references another object:

Print name

The symbol’s name.

Value

The symbol’s current value as a variable.

Function

The symbol’s function definition. It can also hold a symbol, a keymap, or a keyboard macro.

Property list

The symbol’s property list.

The print name cell always holds a string, and cannot be changed. Each of the other three cells can be set to any Lisp object.

The print name cell holds the string that is the name of a symbol. Since symbols are represented textually by their names, it is important not to have two symbols with the same name. The Lisp reader ensures this: every time it reads a symbol, it looks for an existing symbol with the specified name before it creates a new one. To get a symbol’s name, use the function symbol-name (see Creating and Interning Symbols). However, although each symbol has only one unique print name, it is nevertheless possible to refer to that same symbol via different alias names called “shorthands” (see Shorthands).

The value cell holds a symbol’s value as a variable, which is what you get if the symbol itself is evaluated as a Lisp expression. See Variables, for details about how values are set and retrieved, including complications such as local bindings and scoping rules. Most symbols can have any Lisp object as a value, but certain special symbols have values that cannot be changed; these include nil and t, and any symbol whose name starts with ‘:’ (those are called keywords). See Variables that Never Change.

The function cell holds a symbol’s function definition. Often, we refer to “the function foo” when we really mean the function stored in the function cell of foo; we make the distinction explicit only when necessary. Typically, the function cell is used to hold a function (see Functions) or a macro (see Macros). However, it can also be used to hold a symbol (see Symbol Function Indirection), keyboard macro (see Keyboard Macros), keymap (see Keymaps), or autoload object (see Autoloading). To get the contents of a symbol’s function cell, use the function symbol-function (see Accessing Function Cell Contents).

The property list cell normally should hold a correctly formatted property list. To get a symbol’s property list, use the function symbol-plist. See Symbol Properties.

The function cell or the value cell may be void, which means that the cell does not reference any object. (This is not the same thing as holding the symbol void, nor the same as holding the symbol nil.) Examining a function or value cell that is void results in an error, such as ‘Symbol's value as variable is void’.

Because each symbol has separate value and function cells, variables names and function names do not conflict. For example, the symbol buffer-file-name has a value (the name of the file being visited in the current buffer) as well as a function definition (a primitive function that returns the name of the file):

buffer-file-name
     ⇒ "/gnu/elisp/symbols.texi"
(symbol-function 'buffer-file-name)
     ⇒ #<subr buffer-file-name>