summaryrefslogtreecommitdiff
path: root/devdocs/elisp/constant-variables.html
blob: fd0538ba973912e025e5762331b7933dfb92a734 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 <h3 class="section">Variables that Never Change</h3>       <p>In Emacs Lisp, certain symbols normally evaluate to themselves. These include <code>nil</code> and <code>t</code>, as well as any symbol whose name starts with ‘<samp>:</samp>’ (these are called <em>keywords</em>). These symbols cannot be rebound, nor can their values be changed. Any attempt to set or bind <code>nil</code> or <code>t</code> signals a <code>setting-constant</code> error. The same is true for a keyword (a symbol whose name starts with ‘<samp>:</samp>’), if it is interned in the standard obarray, except that setting such a symbol to itself is not an error. </p> <div class="example"> <pre class="example">nil ≡ 'nil
     ⇒ nil
</pre>
<pre class="example">(setq nil 500)
error→ Attempt to set constant symbol: nil
</pre>
</div> <dl> <dt id="keywordp">Function: <strong>keywordp</strong> <em>object</em>
</dt> <dd><p>function returns <code>t</code> if <var>object</var> is a symbol whose name starts with ‘<samp>:</samp>’, interned in the standard obarray, and returns <code>nil</code> otherwise. </p></dd>
</dl> <p>These constants are fundamentally different from the constants defined using the <code>defconst</code> special form (see <a href="defining-variables">Defining Variables</a>). A <code>defconst</code> form serves to inform human readers that you do not intend to change the value of a variable, but Emacs does not raise an error if you actually change it. </p>  <p>A small number of additional symbols are made read-only for various practical reasons. These include <code>enable-multibyte-characters</code>, <code>most-positive-fixnum</code>, <code>most-negative-fixnum</code>, and a few others. Any attempt to set or bind these also signals a <code>setting-constant</code> error. </p><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/Constant-Variables.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Constant-Variables.html</a>
  </p>
</div>