diff options
Diffstat (limited to 'devdocs/elisp/symbol-components.html')
| -rw-r--r-- | devdocs/elisp/symbol-components.html | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/devdocs/elisp/symbol-components.html b/devdocs/elisp/symbol-components.html new file mode 100644 index 00000000..5d2e4bb5 --- /dev/null +++ b/devdocs/elisp/symbol-components.html @@ -0,0 +1,16 @@ + <h3 class="section">Symbol Components</h3> <p>Each symbol has four components (or “cells”), each of which references another object: </p> <dl compact> <dt>Print name</dt> <dd> + <p>The symbol’s name. </p> </dd> <dt>Value</dt> <dd> + <p>The symbol’s current value as a variable. </p> </dd> <dt>Function</dt> <dd> + <p>The symbol’s function definition. It can also hold a symbol, a keymap, or a keyboard macro. </p> </dd> <dt>Property list</dt> <dd> + <p>The symbol’s property list. </p> +</dd> </dl> <p>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. </p> <p>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 <code>symbol-name</code> (see <a href="creating-symbols">Creating Symbols</a>). However, although each symbol has only one unique <em>print name</em>, it is nevertheless possible to refer to that same symbol via different alias names called “shorthands” (see <a href="shorthands">Shorthands</a>). </p> <p>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 <a href="variables">Variables</a>, for details about how values are set and retrieved, including complications such as <em>local bindings</em> and <em>scoping rules</em>. Most symbols can have any Lisp object as a value, but certain special symbols have values that cannot be changed; these include <code>nil</code> and <code>t</code>, and any symbol whose name starts with ‘<samp>:</samp>’ (those are called <em>keywords</em>). See <a href="constant-variables">Constant Variables</a>. </p> <p>The function cell holds a symbol’s function definition. Often, we refer to “the function <code>foo</code>” when we really mean the function stored in the function cell of <code>foo</code>; we make the distinction explicit only when necessary. Typically, the function cell is used to hold a function (see <a href="functions">Functions</a>) or a macro (see <a href="macros">Macros</a>). However, it can also be used to hold a symbol (see <a href="function-indirection">Function Indirection</a>), keyboard macro (see <a href="keyboard-macros">Keyboard Macros</a>), keymap (see <a href="keymaps">Keymaps</a>), or autoload object (see <a href="autoloading">Autoloading</a>). To get the contents of a symbol’s function cell, use the function <code>symbol-function</code> (see <a href="function-cells">Function Cells</a>). </p> <p>The property list cell normally should hold a correctly formatted property list. To get a symbol’s property list, use the function <code>symbol-plist</code>. See <a href="symbol-properties">Symbol Properties</a>. </p> <p>The function cell or the value cell may be <em>void</em>, which means that the cell does not reference any object. (This is not the same thing as holding the symbol <code>void</code>, nor the same as holding the symbol <code>nil</code>.) Examining a function or value cell that is void results in an error, such as ‘<samp>Symbol's value as variable is void</samp>’. </p> <p>Because each symbol has separate value and function cells, variables names and function names do not conflict. For example, the symbol <code>buffer-file-name</code> 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): </p> <div class="example"> <pre class="example">buffer-file-name + ⇒ "/gnu/elisp/symbols.texi" +(symbol-function 'buffer-file-name) + ⇒ #<subr buffer-file-name> +</pre> +</div><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Components.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Components.html</a> + </p> +</div> |
