From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Taylan Kammer <taylan.kammer@gmail.com>
Newsgroups: gmane.lisp.guile.user
Subject: Re: Equality and hashing for new datatypes
Date: Fri, 23 Jun 2023 09:09:20 +0200
Message-ID: <5eac5cec-c7d1-70a5-ffde-ae58c4e36a1c@gmail.com>
References: <3759578.e9J7NaK4W3@bastet>
 <01fa3142-02d8-9bb0-9dfd-5b233aa57bbf@gmail.com> <2803364.tdWV9SEqCh@bastet>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="12601"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
 Thunderbird/102.12.0
To: Philip McGrath <philip@philipmcgrath.com>, guile-user <guile-user@gnu.org>
Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Jun 23 09:10:08 2023
Return-path: <guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org>
Envelope-to: guile-user@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org>)
	id 1qCavn-00037v-Rc
	for guile-user@m.gmane-mx.org; Fri, 23 Jun 2023 09:10:07 +0200
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <guile-user-bounces@gnu.org>)
	id 1qCavE-0002VD-Kl; Fri, 23 Jun 2023 03:09:32 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <taylan.kammer@gmail.com>)
 id 1qCavA-0002Uj-LY
 for guile-user@gnu.org; Fri, 23 Jun 2023 03:09:30 -0400
Original-Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <taylan.kammer@gmail.com>)
 id 1qCav8-0007wW-Qk
 for guile-user@gnu.org; Fri, 23 Jun 2023 03:09:28 -0400
Original-Received: by mail-ej1-x62d.google.com with SMTP id
 a640c23a62f3a-98bcc5338d8so27736466b.1
 for <guile-user@gnu.org>; Fri, 23 Jun 2023 00:09:25 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20221208; t=1687504163; x=1690096163;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:to:subject:user-agent:mime-version:date:message-id:from
 :to:cc:subject:date:message-id:reply-to;
 bh=mEwpX2h2ASsiAQoU2ELLO9v6J1GNbt+vYgU/2Av9Xho=;
 b=gHI/SX/Cf/m365VSxXQgcDzgwNQzdCg3cwRKt2+A2mI0DDhZLV/kDZR2yiThLCAfeR
 y//StK6NqvIWccAdLYCG7/ssFTN2I31/t+kkzmE55Ee2vi6x/zG9j41yPrx4YxuopHEU
 5qLcLO0cDqpYvcVWW7fXzOplyj74lcukIUiyt2vfuUs+g8ASo3nFVeqfhof1niNvNzo5
 yYGWruJ3wzJlPquClXlWWbhNb7Iibus9sSDiElQUaZODAGlKjxJfIp+gck8dWMmV8WBr
 y2ediomyw3KDdM9GgmMrJUcHG6s6373bgZUXKWc/rTFqXc7E3ZdQJmJdMftvHUZoDTyq
 3d4g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20221208; t=1687504163; x=1690096163;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:to:subject:user-agent:mime-version:date:message-id
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=mEwpX2h2ASsiAQoU2ELLO9v6J1GNbt+vYgU/2Av9Xho=;
 b=C/gYYkEoVXzHMIiGnWkKa0YiHuL8Z56giDSUiHpybFHrHWYFuX+NuX9/XRpvXl+/0p
 6abbbN6PMSvgkRPYr6ragbsTDfT4WttpwBc5/koSST5/uay7DUEWIUKFql3b6qyobAA2
 T9UN3jJNThUkqjPufBRp9BiSJmJm5y2IaSc539h5IFF8/U58ShCGuXdd4DJ48R3CVABj
 EvPa9gIIyxWEt99zFZ9/NTnsX3MqD/cL0qNnF5tmzXtoBFr6rLUcJoJcDJioY6otBks7
 TYoxmAhf0XdbStsLPIeRuH9Q+Kx4wBxGy7i3vkABJKnjpC1P/KoJkmzKdnrPq+le2wFX
 6kbQ==
X-Gm-Message-State: AC+VfDysuChM2xu1cRuEDKL33pMpMypMhi1kLFbHdSFmxRhODKJcTyjg
 w6Vl+LhvwsHKpVm0GNw6sgRhf/l2OKc=
X-Google-Smtp-Source: ACHHUZ4FrwMdj9o7e2XmYaXviaNtXKXaJfKNmLmmq3IiqPLEoDhmFHmbRoJhZzND/z7h030KyIU8qg==
X-Received: by 2002:a17:906:53cd:b0:98d:81c7:f01a with SMTP id
 p13-20020a17090653cd00b0098d81c7f01amr689683ejo.62.1687504163298; 
 Fri, 23 Jun 2023 00:09:23 -0700 (PDT)
Original-Received: from [192.168.178.20] (ip-109-090-125-150.um36.pools.vodafone-ip.de.
 [109.90.125.150]) by smtp.gmail.com with ESMTPSA id
 bf18-20020a0564021a5200b0051be86ff767sm1915307edb.70.2023.06.23.00.09.22
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Fri, 23 Jun 2023 00:09:22 -0700 (PDT)
Content-Language: en-US
In-Reply-To: <2803364.tdWV9SEqCh@bastet>
Received-SPF: pass client-ip=2a00:1450:4864:20::62d;
 envelope-from=taylan.kammer@gmail.com; helo=mail-ej1-x62d.google.com
X-Spam_score_int: -21
X-Spam_score: -2.2
X-Spam_bar: --
X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 NICE_REPLY_A=-0.09, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: guile-user@gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Guile related discussions <guile-user.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/guile-user>,
 <mailto:guile-user-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/guile-user>
List-Post: <mailto:guile-user@gnu.org>
List-Help: <mailto:guile-user-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/guile-user>,
 <mailto:guile-user-request@gnu.org?subject=subscribe>
Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org
Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.lisp.guile.user:19060
Archived-At: <http://permalink.gmane.org/gmane.lisp.guile.user/19060>

On 23.06.2023 00:45, Philip McGrath wrote:
> On Thursday, June 22, 2023 7:33:06 AM EDT Taylan Kammer wrote:
>> On 22.06.2023 00:25, Philip McGrath wrote:
>>> Hi,
>>>
>>> What is the recommended way for a library to customize `equal?` and
>>> `equal?` -based hashing for new datatypes it defines?
>>>
>>> I know from [1] that `equal?` can be customized using GOOPS; however, some
>>> projects do not use GOOPS (e.g. [2]), so it would seem more friendly for a
>>> generic library to avoid it. Also, it is not clear if the same mechanism
>>> is
>>> even an option for customizing `equal-hash` to match `equal?`.
>>>
>>> I'm looking for something like Racket's `gen:equal+hash` [3] or Chez
>>> Scheme's `record-equal-procedure` and `record-hash-procedure` [4].
>>>
>>> This came up while I was working on a portable version of the immutable
>>> hash-table implementations from Racket-on-Chez.
>>>
>>> -Philip
>>>
>>> [1]:
>>> https://www.gnu.org/software/guile/manual/html_node/GOOPS-Object-Miscella
>>> ny.html [2]:
>>> https://lists.gnu.org/archive/html/info-gnu/2023-05/msg00005.html [3]:
>>> https://docs.racket-lang.org/reference/Equality.html#%28part._.Implementi
>>> ng_.Equality_for_.Custom_.Types%29 [4]:
>>> https://cisco.github.io/ChezScheme/csug9.5/objects.html#./objects:h14
>> Hi Philip,
>>
>> You can use SRFI 69 hash tables in Guile.  This library offers a way to
>> specify the equality and hash procedures that should be used by a hash
>> table, e.g.:
>>
>> [...]
>>
>> Note that this doesn't affect the behavior of the standard 'equal?'
>> procedure, it only affects the SRFI 69 hash table operations on the created
>> hash table.
>>
>> I currently don't remember whether Guile's own non-portable hash table
>> library supports the same feature.  It probably does in some way.
>>
> 
> Thanks, but this is the opposite of what I want to do. The library I'm porting 
> already supports creating tables with custom equality and hashing functions. 
> What I'm trying to do is make the standard `equal?` procedure recognize when 
> two of my table values are semantically the same even if internal 
> implementation details differ.
> 
> (Note also that SRFI 69 and other libraries provide *mutable* hash tables. The 
> Racket-on-Chez library I'm porting provides immutable hash tables, more 
> properly Hash Array Mapped Tries, as made famous by Clojure.)
> 
> -Philip

Ah, apologies then.  As far as I know, there's no other way to do that in Guile
than with GOOPS, which you've already mentioned.

In standard Scheme there's no way to do it at all.  I don't think there's even
an SRFI for it (I just searched a bit, out of curiosity, couldn't find anything).

-- 
Taylan