[Openmcl-devel] Is it safe to make hash tables with non-standard tests?
Tom Emerson
tremerson at gmail.com
Sun Jul 14 18:45:05 PDT 2013
WRT symbols, fair enough. I'd assumed #'string= for strings, not
necessarily things that can become strings. I guess wrapping in symbol-name
is a portable way to do it. But as Gary says, if you're not worried about
portability then #'string= will be what you want.
And in response to Gary, not trying to make or win an argument.
On Sun, Jul 14, 2013 at 9:02 PM, Ron Garret <ron at flownet.com> wrote:
> EQUALP doesn't do the Right Thing with symbols:
>
> ? (equalp 'foo "FOO")
> NIL
> ? (string= 'foo "FOO")
> T
>
> Also, EQUALP is a security risk. It's vulnerable to denial-of-service
> attacks if you feed it e.g. a circular list.
>
> rg
>
> On Jul 14, 2013, at 4:49 PM, 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
>
>
>
--
Tom Emerson
tremerson at gmail.com
http://www.dreamersrealm.net/tree
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20130714/4ec1bb8b/attachment.htm>
More information about the Openmcl-devel
mailing list