[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Comparing hash table objects
From: |
Ihor Radchenko |
Subject: |
Re: Comparing hash table objects |
Date: |
Sat, 11 Jun 2022 13:52:25 +0800 |
Richard Stallman <rms@gnu.org> writes:
> It clearly can be useful to compare hash tables for equivalence
> of contents. I see two ways to offer that facility:
>
> * As a new function. That would be upward-compatible.
I have seen various variants of such function in third-party packages
and just in internet search results.
For example, ht-equal? from
https://github.com/Wilfred/ht.el/blob/master/ht.el:
(defun ht-equal? (table1 table2)
"Return t if TABLE1 and TABLE2 have the same keys and values.
Does not compare equality predicates."
(declare (side-effect-free t))
(let ((keys1 (ht-keys table1))
(keys2 (ht-keys table2))
(sentinel (make-symbol "ht-sentinel")))
(and (equal (length keys1) (length keys2))
(--all?
(equal (ht-get table1 it)
(ht-get table2 it sentinel))
keys1))))
However, it will not help with the problem of comparing objects
containing hash tables. Unless those obejcts also define special
comparison function (which is inconvenient).
> * By making `equal' compare them that way. That would fit the spirit
> of `equal', but could break some existing uses of `equal'.
I'd say that using `equal' on hash tables with the actual intention of
comparing tables by `eq' is calling for a trouble. At least, it is
misleading.
Best,
Ihor
- Comparing hash table objects, Ihor Radchenko, 2022/06/08
- Re: Comparing hash table objects, Andreas Schwab, 2022/06/08
- Re: Comparing hash table objects, Ihor Radchenko, 2022/06/08
- Re: Comparing hash table objects, Richard Stallman, 2022/06/10
- Re: Comparing hash table objects,
Ihor Radchenko <=
- Re: Comparing hash table objects, Stefan Monnier, 2022/06/11
- Re: Comparing hash table objects, Ihor Radchenko, 2022/06/12
- Re: Comparing hash table objects, Sam Steingold, 2022/06/12
- Re: Comparing hash table objects, Stefan Monnier, 2022/06/13
- Re: Comparing hash table objects, Sam Steingold, 2022/06/13