1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-12 22:40:46 -08:00
emacs/doc
Stefan Kangas dd0dd87e3a New function 'hash-table-contains-p'
This function tests whether a given key is present in a hash table.
Emacs Lisp has long lacked a standard way to do this, leading users to
write one of:

    (not (eq (gethash key table 'missing) 'missing))
or
    (gethash key table)

This idiom is error-prone (when 'missing' or 'nil' are valid values),
and it obscures intent.  The new function avoids such pitfalls,
improves readability, and makes the intent explicit:

    (hash-table-contains-p key table)

The name 'hash-table-contains-p' exists in other Lisp dialects (e.g.,
SRFI-125), and follows the precedent of 'seq-contains-p'.  Other
alternatives considered include `hash-table-has-key-p` and
`hash-table-key-exists-p`, but none were clearly better.

This was previously discussed in 2018, and all comments were positive,
but the proposed patch (implementing it in C) was never pushed:
https://lists.gnu.org/r/emacs-devel/2018-02/msg00424.html

* lisp/subr.el (hash-table-contains-p): New function.
* lisp/emacs-lisp/shortdoc.el (hash-table):
* doc/lispref/hash.texi (Other Hash): Document the new function.
* test/lisp/subr-tests.el (hash-table-contains-p): New test.
2025-03-29 14:59:36 +01:00
..
emacs ; Fix a merge snafu. 2025-03-29 08:54:30 -04:00
lispintro Don't recommend legacy keymap functions in documentation 2025-03-11 21:19:13 +01:00
lispref New function 'hash-table-contains-p' 2025-03-29 14:59:36 +01:00
man Remove ctags program 2025-03-22 11:57:29 -07:00
misc ; Fix a merge snafu. 2025-03-29 08:54:30 -04:00
translations Update copyright year to 2025 2025-01-02 18:39:42 +01:00