From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: Comparing two hash tables for equality? Date: Tue, 28 Aug 2018 03:37:46 -0400 Message-ID: <87r2ijym9h.fsf@netris.org> References: <2418985.EcWt8OQBW1@aleksandar-ixtreme-m5740> <87o9dovj4z.fsf@netris.org> <21644757.cYmYgW3VaQ@aleksandar-ixtreme-m5740> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1535441862 25386 195.159.176.226 (28 Aug 2018 07:37:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 28 Aug 2018 07:37:42 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: guile-user@gnu.org To: Aleksandar Sandic Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Aug 28 09:37:38 2018 Return-path: Envelope-to: guile-user@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 1fuYZG-0006T0-1L for guile-user@m.gmane.org; Tue, 28 Aug 2018 09:37:38 +0200 Original-Received: from localhost ([::1]:36772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuYbL-0002vm-TI for guile-user@m.gmane.org; Tue, 28 Aug 2018 03:39:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuYay-0002vh-BT for guile-user@gnu.org; Tue, 28 Aug 2018 03:39:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuYau-0004jk-6B for guile-user@gnu.org; Tue, 28 Aug 2018 03:39:24 -0400 Original-Received: from world.peace.net ([64.112.178.59]:49930) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fuYau-0004jL-24 for guile-user@gnu.org; Tue, 28 Aug 2018 03:39:20 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fuYat-0001iH-3l; Tue, 28 Aug 2018 03:39:19 -0400 In-Reply-To: <21644757.cYmYgW3VaQ@aleksandar-ixtreme-m5740> (Aleksandar Sandic's message of "Mon, 27 Aug 2018 23:53:09 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.112.178.59 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14801 Archived-At: Hi Aleksandar, Aleksandar Sandic writes: >> An equality test on hash tables needs to know how to compare the keys >> and how to compare the values. There's no way to pass those additional >> arguments to 'equal?', so it can't do that job. > It has to compare the values, but not the keys. There's an implicit equality test on keys every time you perform a hash table lookup. By using 'hash-ref' and 'hash-get-handle', you are implicitly using 'equal?' to compare the keys in the hash table with the key that you're asking to look up. Guile's native hash tables are unusual in that they do not internally keep track of which equality test on keys to use. Instead, it is your responsibility to consistently use the functions corresponding to same equality test in all accesses to a given hash table. As the Guile manual states: Like the association list functions, the hash table functions come in several varieties, according to the equality test used for the keys. Plain =E2=80=98hash-=E2=80=99 functions use =E2=80=98equal?=E2=80=99, =E2= =80=98hashq-=E2=80=99 functions use =E2=80=98eq?=E2=80=99, =E2=80=98hashv-=E2=80=99 functions use =E2=80=98eqv?=E2=80=99, and the = =E2=80=98hashx-=E2=80=99 functions use an application supplied test. A single =E2=80=98make-hash-table=E2=80=99 creates a hash table suitab= le for use with any set of functions, but it=E2=80=99s imperative that just one set = is then used consistently, or results will be unpredictable. So, your 'hash-table-equal?' predicate implicitly assumes that the hash tables passed to it were populated using 'hash-set!' or 'hash-create-handle!'. If it is applied to a hash table that was populated with the 'hashq-*!', 'hashv-*!', or 'hashx-*!' procedures, then the results will be unpredictable. My 'hash-table=3D?' predicate makes the same implicit assumption. Mark