[cdr-discuss] CDR-2 -- register-test-designator vs. keyword parameters

Why does genhash use the technique of registering hashing functions and equality predicates instead of using keyword parameters? Both LispWorks and Allegro use keyword parameters so that you can say (make-hash-table :test 'my-equal? :hash-function 'my-hash) http://www.lispworks.com/documentation/lw50/LWRM/html/lwref-86.htm http://www.franz.com/support/documentation/8.0/doc/implementation.htm#cl-mak... I find this more natural and intuitive that having a separate register-test-designator function. The register-test-designator seems too much like "action at a distance". To be fair SBCL has a technique similar to the CDR-2 proposal (see sb-ext::define-hash-table-test). Cheers, Chris Dean

Chris Dean writes:
Why does genhash use the technique of registering hashing functions and equality predicates instead of using keyword parameters?
Primarily so that a "sufficiently clever" implementation can go forth and analyse the hash function and equality test predicate at time of registration and possibly construct custom classes and methods for it. Secondarily, to reinforce the coupling between an equality test predicate and a hash function. //Ingvar

Ingvar <ingvar@hexapodia.net> writes:
Chris Dean writes:
Why does genhash use the technique of registering hashing functions and equality predicates instead of using keyword parameters?
Primarily so that a "sufficiently clever" implementation can go forth and analyse the hash function and equality test predicate at time of registration and possibly construct custom classes and methods for it.
Secondarily, to reinforce the coupling between an equality test predicate and a hash function.
I see, thanks. For me, -1 for this idea. While it's a worthwhile goal to couple these two concepts it seems more complicated than just providing keyword parameters. Keywords have the obvious downside of the user mismatching the test and hash, but I believe this is outweighed by the simplicity of the design. Certainly either position is subject to some debate! One thing I like about the keyword design is that if a user prefers the registration design, then she can implement it herself on top of the keyword design. The reverse (implementing the keyword design on top of the registration design) is more difficult or has some performance implications. Cheers, Chris Dean

Chris Dean <ctdean@sokitomi.com> writes:
One thing I like about the keyword design is that if a user prefers the registration design, then she can implement it herself on top of the keyword design. The reverse (implementing the keyword design on top of the registration design) is more difficult or has some performance implications.
One of the downsides of the keyword design is that it doesn't express users intention as clearly, and requires users to express the same intention over and over again. While this doesn't really belong with CDR 2, I'll use this space to note that :KEY argument would be more usefull to me that a custom test and hash function most of the time -- and that would actually make more sense in the table itself. (make-hash-table :test 'eq :key 'car) would be a hash-table whose keys are hashed and compared only based on their cars. Cheers, -- Nikodemus Schemer: "Buddha is small, clean, and serious." Lispnik: "Buddha is big, has hairy armpits, and laughs."

Nikodemus Siivola <nikodemus@random-state.net> writes:
and requires users to express the same intention over and over again.
Not really, since if they have the same test/hash pair can just create a helper function: (defun make-people-hash-table () (make-generic-hashtable :test 'people-test :hash-function 'people-hash))
(make-hash-table :test 'eq :key 'car)
would be a hash-table whose keys are hashed and compared only based on their cars.
An excellent idea! Why not add that? If one were to stick with the register-test-designator design, I would suggest that we change the name of the keyword parameter from TEST to something else to reflect that in the general case it's not a test but a designator that is being specified: (make-generic-hashtable &key size (designator ’eql)) Cheers, Chris Dean
participants (3)
-
Chris Dean
-
Ingvar
-
Nikodemus Siivola