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

Tom Emerson tremerson at gmail.com
Sun Jul 14 23:49:51 UTC 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clozure.com/pipermail/openmcl-devel/attachments/20130714/6d2c9e5c/attachment.html>


More information about the Openmcl-devel mailing list