From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: RE: [PATCH] Add new function to test whether a key is present in a hash table. Date: Thu, 15 Feb 2018 14:08:42 -0800 (PST) Message-ID: <2ce9b5db-b17d-415c-8dc6-6046a31269be@default> References: <<20180215203406.64372-1-phst@google.com>> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1518732596 31820 195.159.176.226 (15 Feb 2018 22:09:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 15 Feb 2018 22:09:56 +0000 (UTC) Cc: Philipp Stephani To: Philipp Stephani , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Feb 15 23:09:52 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1emRik-0007Cy-AQ for ged-emacs-devel@m.gmane.org; Thu, 15 Feb 2018 23:09:38 +0100 Original-Received: from localhost ([::1]:36718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emRkm-0001k2-3M for ged-emacs-devel@m.gmane.org; Thu, 15 Feb 2018 17:11:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emRi1-0000Bh-Ln for emacs-devel@gnu.org; Thu, 15 Feb 2018 17:08:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emRhw-00024w-Ms for emacs-devel@gnu.org; Thu, 15 Feb 2018 17:08:53 -0500 Original-Received: from userp2120.oracle.com ([156.151.31.85]:50306) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emRhw-000240-At for emacs-devel@gnu.org; Thu, 15 Feb 2018 17:08:48 -0500 Original-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1FM6m4i191696; Thu, 15 Feb 2018 22:08:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=3QKc9vqrONguSHjuTegiJfNj2FpSHEbpeVwrrcTgajM=; b=cCA53k2jG1MNKU5ZrOspve9ZqjV99Rm+Yy6LNkyJTcQ+/pZFotuDEjhd+FjX1l/0I99O i13inxCBDdqCOvUgLjZv63O3m7vQMPSA4pfL4H+LYQSatl4awzm6V++kh/CgALZfvOCN rrHvRY6nCytQiFiAXpHqC9yQra7Dv8t3VyQkjHXbGRwUkgFpGL+yR+n4L2YpvV32JciA CXxlkIc1Vd/vX5Hmvp9eD2HTrljuKdHBMevF9oB4s9BikrDrXpiW6uO2rvbvB7nZHX3o 87rrsgpDEGVPZg/VaFaBzlb1C2u1Maw5DG1udSvz9UE+T2rK//VDL0d639dDsMDt7ZtR oQ== Original-Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2g5g6s8tkq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Feb 2018 22:08:44 +0000 Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w1FM8hle015110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 15 Feb 2018 22:08:43 GMT Original-Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1FM8hWI003735; Thu, 15 Feb 2018 22:08:43 GMT In-Reply-To: <<20180215203406.64372-1-phst@google.com>> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4654.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8806 signatures=668672 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802150265 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:222776 Archived-At: > 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. Glad to see this. Everyone was coding their own (in Lisp). > +While it might be tempting to use @code{gethash} to check whether a > +key is present in a hash table, keep in mind that you often need to > +distinguish between @var{key} being absent and @var{key} being mapped > +to @var{default}. To easily distinguish between these two cases, > +there's another function to explicitly check whether a key is present: > + > +@defun hash-table-contains-p key table > +This function looks up @var{key} in @var{table}; it returns @code{t} > +if @var{key} is present, and @code{nil} otherwise. The associated > +value is ignored. 1. I don't think we need to say "The associated value is ignored". Nothing suggests that it would be used in any way. 2. The function name should have `key' in it, I think. Suggestion: `hash-table-contains-key-p' or even just `hash-table-key-p'. 3. Another possibility could be to return, as the true value, a cons of the value associated with the key. IOW, instead of returning `t' we would return `(THE-VALUE)'. If this is not particularly costly it might be a bit more useful. ___ Related: Bug #30458 asks for a function that tests whether a hash table contains an entry with a given value. More precisely, it would return the list of keys with that value, so nil would mean the value is absent altogether.