[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Equality and hashing for new datatypes
From: |
Philip McGrath |
Subject: |
Re: Equality and hashing for new datatypes |
Date: |
Thu, 22 Jun 2023 18:45:54 -0400 |
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
signature.asc
Description: This is a digitally signed message part.