Subject: Re: a short article about equality in Lisp (for beginners)
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 07 Aug 2004 19:49:43 -0500
Newsgroups: comp.lang.lisp
Message-ID: <XaOdnUqusoQ65YjcRVn-qA@speakeasy.net>
Robert Strandh  <strandh@labri.fr> wrote:
+---------------
| Perhaps this is the moment to submit my modest proposal for a new
| equality predicate + hash function.
...
| The standard specifies only four types of hash tables possible,
| according to whether the equality function is eq, eql, equal or equalp.
+---------------

Are you familiar with EXTENSIONS:DEFINE-HASH-TABLE-TEST in CMUCL?
(...and presumably in SBCL as well?)

    The hash-tables defined by Common Lisp have limited utility
    because they are limited to testing their keys using the equality
    predicates provided by (pre-CLOS) Common Lisp. CMUCL overcomes
    this limitation by allowing its users to specify new hash table
    tests and hashing methods. The hashing method must also be
    specified, since the compiler is unable to determine a good
    hashing function for an arbitrary equality (equivalence) predicate.

    [Function]
    define-hash-table-test hash-table-test-name test-function hash-function

    The hash-table-test-name must be a symbol. The test-function takes
    two objects and returns true iff they are the same. The hash-function
    takes one object and returns two values: the (positive fixnum) hash
    value and true if the hashing depends on pointer values and will
    have to be redone if the object moves.

    To create a hash-table using this new ``test''
    (really, a test/hash-function pair), use
    (MAKE-HASH-TABLE :TEST hash-table-test-name ...).

I believe that this is a simpler protocol that does not require
introducing the notion of "situations" or the generic functions
they depend on.

As usual with CMUCL/SBCL, the code is available for perusal and/or
re-use in other implementations.


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607