diff options
Diffstat (limited to 'devdocs/elisp/variable-scoping.html')
| -rw-r--r-- | devdocs/elisp/variable-scoping.html | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/devdocs/elisp/variable-scoping.html b/devdocs/elisp/variable-scoping.html new file mode 100644 index 00000000..df18606a --- /dev/null +++ b/devdocs/elisp/variable-scoping.html @@ -0,0 +1,31 @@ + <h3 class="section">Scoping Rules for Variable Bindings</h3> <p>When you create a local binding for a variable, that binding takes effect only within a limited portion of the program (see <a href="local-variables">Local Variables</a>). This section describes exactly what this means. </p> <p>Each local binding has a certain <em>scope</em> and <em>extent</em>. <em>Scope</em> refers to <em>where</em> in the textual source code the binding can be accessed. <em>Extent</em> refers to <em>when</em>, as the program is executing, the binding exists. </p> <p>By default, the local bindings that Emacs creates are <em>dynamic bindings</em>. Such a binding has <em>dynamic scope</em>, meaning that any part of the program can potentially access the variable binding. It also has <em>dynamic extent</em>, meaning that the binding lasts only while the binding construct (such as the body of a <code>let</code> form) is being executed. </p> <p>Emacs can optionally create <em>lexical bindings</em>. A lexical binding has <em>lexical scope</em>, meaning that any reference to the variable must be located textually within the binding construct<a id="DOCF10" href="#FOOT10"><sup>10</sup></a>. It also has <em>indefinite extent</em>, meaning that under some circumstances the binding can live on even after the binding construct has finished executing, by means of special objects called <em>closures</em>. </p> <p>The following subsections describe dynamic binding and lexical binding in greater detail, and how to enable lexical binding in Emacs Lisp programs. </p> <table class="menu" border="0" cellspacing="0"> <tr> +<td align="left" valign="top">• <a href="dynamic-binding" accesskey="1">Dynamic Binding</a> +</td> +<td> </td> +<td align="left" valign="top">The default for binding local variables in Emacs. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Dynamic-Binding-Tips.html" accesskey="2">Dynamic Binding Tips</a> +</td> +<td> </td> +<td align="left" valign="top">Avoiding problems with dynamic binding. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="lexical-binding" accesskey="3">Lexical Binding</a> +</td> +<td> </td> +<td align="left" valign="top">A different type of local variable binding. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="using-lexical-binding" accesskey="4">Using Lexical Binding</a> +</td> +<td> </td> +<td align="left" valign="top">How to enable lexical binding. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="converting-to-lexical-binding" accesskey="5">Converting to Lexical Binding</a> +</td> +<td> </td> +<td align="left" valign="top">Convert existing code to lexical binding. </td> +</tr> </table><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/Variable-Scoping.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Variable-Scoping.html</a> + </p> +</div> |
