[Openmcl-devel] Is it safe to make hash tables with non-standard tests?

Gary Byers gb at clozure.com
Sun Jul 14 17:48:15 PDT 2013


If the question was "can TEST functions other than EQ/EQL/EQUAL/EQUALP
be used non-portably in CCL, and should that be considered a supported
extension that should be documented ?", the answer is "yes".  IIRC, in
CLtL1 EQUALP wasn't a standard test function, and supporting arbitrary
test functions (and user-provided hashing functions) was one way of
supporting EQUALP as a test.

If the question was "is this a non-portable extenstion ?" ... I don't
think that that was the question.

If the question was "is there a compelling reason to use a non-standard
test function (other than typechecking and whatever the performance tradeoffs
are at the moment), and is such a reason more compelling than portability
concerns that one may or may not have ?" ... well, that's a good question
to ask and one that different people can have good reasons to answer differently.

On Sun, 14 Jul 2013, Tom Emerson wrote:

> You don't need to: using 'equal as your test achieves the same result.
> Welcome to Clozure Common Lisp Version 1.9-r15757 ?(LinuxX8664)!
> ? (defvar foo (make-hash-table :test 'equal))
> #<HASH-TABLE :TEST EQUAL size 0/60 #x3020006F2C3D>
> ? (setf (gethash "abc" foo) 100)
> 100
> ? (gethash "abc" foo)
> 100
> T
> ? (gethash "ABC" foo)
> NIL
> NIL
> 
> If instead you want the test to be string-equal then use 'equalp
> 
> ? (setq foo (make-hash-table :test 'equalp))
> #<HASH-TABLE :TEST EQUALP size 0/60 #x3020006F9D5D>
> ? (setf (gethash "abc" foo) 100)
> 100
> ? (gethash "abc" foo)
> 100
> T
> ? (gethash "ABC" foo)
> 100
> T
> 
> This is portable: same results in SBCL.
> 
> 
> 
> On Sun, Jul 14, 2013 at 3:53 PM, Ron Garret <ron at flownet.com> wrote:
>       I need a string= hash table, which is not in the standard. ?It
>       appears that CCL can actually make one:
>
>       (make-hash-table :test 'string= :hash-function 'sxhash)
>
>       This seems to do the Right Thing, but ?it's not documented. ?Is
>       it safe to use this feature?
>
>       rg
>
>       _______________________________________________
>       Openmcl-devel mailing list
>       Openmcl-devel at clozure.com
>       http://clozure.com/mailman/listinfo/openmcl-devel
> 
> 
> 
> 
> --
> Tom Emerson
> tremerson at gmail.com
> http://www.dreamersrealm.net/tree
> 
>



More information about the Openmcl-devel mailing list