summaryrefslogtreecommitdiff
path: root/devdocs/elisp/void-variables.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/elisp/void-variables.html')
-rw-r--r--devdocs/elisp/void-variables.html51
1 files changed, 51 insertions, 0 deletions
diff --git a/devdocs/elisp/void-variables.html b/devdocs/elisp/void-variables.html
new file mode 100644
index 00000000..dfcd140d
--- /dev/null
+++ b/devdocs/elisp/void-variables.html
@@ -0,0 +1,51 @@
+ <h3 class="section">When a Variable is Void</h3> <p>We say that a variable is void if its symbol has an unassigned value cell (see <a href="symbol-components">Symbol Components</a>). </p> <p>Under Emacs Lisp’s default dynamic scoping rule (see <a href="variable-scoping">Variable Scoping</a>), the value cell stores the variable’s current (local or global) value. Note that an unassigned value cell is <em>not</em> the same as having <code>nil</code> in the value cell. The symbol <code>nil</code> is a Lisp object and can be the value of a variable, just as any other object can be; but it is still a value. If a variable is void, trying to evaluate the variable signals a <code>void-variable</code> error, instead of returning a value. </p> <p>Under the optional lexical scoping rule, the value cell only holds the variable’s global value—the value outside of any lexical binding construct. When a variable is lexically bound, the local value is determined by the lexical environment; hence, variables can have local values even if their symbols’ value cells are unassigned. </p> <dl> <dt id="makunbound">Function: <strong>makunbound</strong> <em>symbol</em>
+</dt> <dd>
+<p>This function empties out the value cell of <var>symbol</var>, making the variable void. It returns <var>symbol</var>. </p> <p>If <var>symbol</var> has a dynamic local binding, <code>makunbound</code> voids the current binding, and this voidness lasts only as long as the local binding is in effect. Afterwards, the previously shadowed local or global binding is reexposed; then the variable will no longer be void, unless the reexposed binding is void too. </p> <p>Here are some examples (assuming dynamic binding is in effect): </p> <div class="example"> <pre class="example">(setq x 1) ; <span class="roman">Put a value in the global binding.</span>
+ ⇒ 1
+(let ((x 2)) ; <span class="roman">Locally bind it.</span>
+ (makunbound 'x) ; <span class="roman">Void the local binding.</span>
+ x)
+error→ Symbol's value as variable is void: x
+</pre>
+<pre class="example">x ; <span class="roman">The global binding is unchanged.</span>
+ ⇒ 1
+
+(let ((x 2)) ; <span class="roman">Locally bind it.</span>
+ (let ((x 3)) ; <span class="roman">And again.</span>
+ (makunbound 'x) ; <span class="roman">Void the innermost-local binding.</span>
+ x)) ; <span class="roman">And refer: it’s void.</span>
+error→ Symbol's value as variable is void: x
+</pre>
+
+<pre class="example">(let ((x 2))
+ (let ((x 3))
+ (makunbound 'x)) ; <span class="roman">Void inner binding, then remove it.</span>
+ x) ; <span class="roman">Now outer <code>let</code> binding is visible.</span>
+ ⇒ 2
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="boundp">Function: <strong>boundp</strong> <em>variable</em>
+</dt> <dd>
+<p>This function returns <code>t</code> if <var>variable</var> (a symbol) is not void, and <code>nil</code> if it is void. </p> <p>Here are some examples (assuming dynamic binding is in effect): </p> <div class="example"> <pre class="example">(boundp 'abracadabra) ; <span class="roman">Starts out void.</span>
+ ⇒ nil
+</pre>
+<pre class="example">(let ((abracadabra 5)) ; <span class="roman">Locally bind it.</span>
+ (boundp 'abracadabra))
+ ⇒ t
+</pre>
+<pre class="example">(boundp 'abracadabra) ; <span class="roman">Still globally void.</span>
+ ⇒ nil
+</pre>
+<pre class="example">(setq abracadabra 5) ; <span class="roman">Make it globally nonvoid.</span>
+ ⇒ 5
+</pre>
+<pre class="example">(boundp 'abracadabra)
+ ⇒ t
+</pre>
+</div> </dd>
+</dl><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 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/Void-Variables.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Void-Variables.html</a>
+ </p>
+</div>