summaryrefslogtreecommitdiff
path: root/devdocs/elisp/hash-access.html
blob: 58b2764c1de81b7ef64b71065c2fcc3607981660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 <h3 class="section">Hash Table Access</h3>   <p>This section describes the functions for accessing and storing associations in a hash table. In general, any Lisp object can be used as a hash key, unless the comparison method imposes limits. Any Lisp object can also be used as the value. </p> <dl> <dt id="gethash">Function: <strong>gethash</strong> <em>key table &amp;optional default</em>
</dt> <dd><p>This function looks up <var>key</var> in <var>table</var>, and returns its associated <var>value</var>—or <var>default</var>, if <var>key</var> has no association in <var>table</var>. </p></dd>
</dl> <dl> <dt id="puthash">Function: <strong>puthash</strong> <em>key value table</em>
</dt> <dd><p>This function enters an association for <var>key</var> in <var>table</var>, with value <var>value</var>. If <var>key</var> already has an association in <var>table</var>, <var>value</var> replaces the old associated value. This function always returns <var>value</var>. </p></dd>
</dl> <dl> <dt id="remhash">Function: <strong>remhash</strong> <em>key table</em>
</dt> <dd>
<p>This function removes the association for <var>key</var> from <var>table</var>, if there is one. If <var>key</var> has no association, <code>remhash</code> does nothing. </p> <p><b>Common Lisp note:</b> In Common Lisp, <code>remhash</code> returns non-<code>nil</code> if it actually removed an association and <code>nil</code> otherwise. In Emacs Lisp, <code>remhash</code> always returns <code>nil</code>. </p>
</dd>
</dl> <dl> <dt id="clrhash">Function: <strong>clrhash</strong> <em>table</em>
</dt> <dd><p>This function removes all the associations from hash table <var>table</var>, so that it becomes empty. This is also called <em>clearing</em> the hash table. <code>clrhash</code> returns the empty <var>table</var>. </p></dd>
</dl> <dl> <dt id="maphash">Function: <strong>maphash</strong> <em>function table</em>
</dt> <dd>
<p>This function calls <var>function</var> once for each of the associations in <var>table</var>. The function <var>function</var> should accept two arguments—a <var>key</var> listed in <var>table</var>, and its associated <var>value</var>. <code>maphash</code> returns <code>nil</code>. </p>
</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/Hash-Access.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Hash-Access.html</a>
  </p>
</div>