[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [PATCH] Add new function to test whether a key is present in a hash
From: |
Drew Adams |
Subject: |
RE: [PATCH] Add new function to test whether a key is present in a hash table. |
Date: |
Thu, 15 Feb 2018 17:03:37 -0800 (PST) |
> > Such a function is useful because in Emacs Lisp, 'gethash'
> > cannot return whether the key is present as in Common Lisp,
> > and using 'gethash' alone to test for presence is nontrivial.
>
> We could also implement it in Elisp:
> (defun hash-table-contains-p (key table)
> (let ((x '(:hash-table-contains-p)))
> (not (eq x (gethash key table x)))))
Yes, as I said:
Everyone was coding their own (in Lisp).
using a unique cons, uninterned symbol, or
some other unique object.
Philipp used an uninterned symbol:
(let ((uniq-symb '#:void))
(not (eq uniq-symb (gethash key table uniq-symb))))
I (like you) used a unique cons:
(let ((uniq-cons (cons 1 1)))
(not (eq uniq-cons (gethash key table uniq-cons))))
But isn't it better to define this in C?
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28753