Re: [PATCH] Implement `equal' for hash tables

Richard Stallman <[email protected]> Sun, 09 Aug 2026 15:40:47 -0400
Newsgroups gmane.emacs.devel
Message-ID <[email protected]>
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > >>> Hash tables are equal if they have equal atoms, weakness, and equality
  > >>> and hash functions.
  > >>>
  > >>> (This also means that equal of structures which contain hash tables is
  > >>> useful now, too, which is really the reason I implemented this: right
  > >>> now, hash tables are a sort of poison pill which render any object into
  > >>> which they are inserted unequal with all others.  No more.)
  > >>
  > >> Is it useful in a programming language for hash table objects to be
  > >> directly comparable like this?  I'm not sure that it is.
  > >
  > > I'm sure it's useful at times, tho I agree with Eli that a motivating
  > > example would be appreciated.  The behavior of `equal` (in terms of which
  > > objects are compared structurally and which objects use just `eq`) is
  > > largely arbitrary.

It is not arbitrary -- there is a logic behind it.  For each data
type, we have an idea of how such objects are typically used, which
gives a suggestion of what people are likely to want.

This relates to how the objects print and whether they are readable.
It also relates to other aspects of how they behave.

Consider, for instance, buffers and strings.  Both contain text with
properties -- in that, they are alike.  However, strings print as
their contents, and are readable, whereas buffers print using their
names, have lots of other internal state, and are not readable.

The way `equal' handles those types is coherent with those
differences.  Two distinct strings are equal if they print the same;
two distinct buffers are not equal.

Most unusual "internal" data types are not readable, and it would
not make sense.

Hash tables are a bit funny because they could make sense as readable.

Maybe we would like to be able to flag each hash table as "readable"
or "unreadable".  (Those two are not really good terms but I can't
think of better ones just now.)

Unreadable hash tables would print and compare as they do now.  A
readable hash table would print showing all its contents and would
read back into a similar hash table.  Readable hash tables would
compare equal-style.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)