diff options
Diffstat (limited to 'devdocs/elisp/accessing-variables.html')
| -rw-r--r-- | devdocs/elisp/accessing-variables.html | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/devdocs/elisp/accessing-variables.html b/devdocs/elisp/accessing-variables.html new file mode 100644 index 00000000..abbe9803 --- /dev/null +++ b/devdocs/elisp/accessing-variables.html @@ -0,0 +1,34 @@ + <h3 class="section">Accessing Variable Values</h3> <p>The usual way to reference a variable is to write the symbol which names it. See <a href="symbol-forms">Symbol Forms</a>. </p> <p>Occasionally, you may want to reference a variable which is only determined at run time. In that case, you cannot specify the variable name in the text of the program. You can use the <code>symbol-value</code> function to extract the value. </p> <dl> <dt id="symbol-value">Function: <strong>symbol-value</strong> <em>symbol</em> +</dt> <dd> +<p>This function returns the value stored in <var>symbol</var>’s value cell. This is where the variable’s current (dynamic) value is stored. If the variable has no local binding, this is simply its global value. If the variable is void, a <code>void-variable</code> error is signaled. </p> <p>If the variable is lexically bound, the value reported by <code>symbol-value</code> is not necessarily the same as the variable’s lexical value, which is determined by the lexical environment rather than the symbol’s value cell. See <a href="variable-scoping">Variable Scoping</a>. </p> <div class="example"> <pre class="example">(setq abracadabra 5) + ⇒ 5 +</pre> +<pre class="example">(setq foo 9) + ⇒ 9 +</pre> + +<pre class="example">;; <span class="roman">Here the symbol <code>abracadabra</code></span> +;; <span class="roman">is the symbol whose value is examined.</span> +(let ((abracadabra 'foo)) + (symbol-value 'abracadabra)) + ⇒ foo +</pre> + +<pre class="example">;; <span class="roman">Here, the value of <code>abracadabra</code>,</span> +;; <span class="roman">which is <code>foo</code>,</span> +;; <span class="roman">is the symbol whose value is examined.</span> +(let ((abracadabra 'foo)) + (symbol-value abracadabra)) + ⇒ 9 +</pre> + +<pre class="example">(symbol-value 'abracadabra) + ⇒ 5 +</pre> +</div> </dd> +</dl><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/Accessing-Variables.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Accessing-Variables.html</a> + </p> +</div> |
