Re: [Sawfish] hash table and concat |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/sawfish Archives
]
On 25/09/11 21:35, fuchur wrote:
> Hi,
>
> I can't work with hash tables and concat. In sawfish-client i type:
>
> (require 'rep.data.tables)
> (define test-cache (make-weak-table eq-hash eq))
> (define (cache my-name)
> (or
> (table-ref test-cache my-name)
> (table-set test-cache my-name 'image)))
>
> (cache 'first-name)
> image
>
> if i now type:
> (table-ref test-cache 'first-name)
> image
>
> it's returns image like expected.
>
>
>
>
> If i use concat like this:
>
> (require 'rep.data.tables)
> (define test-cache (make-weak-table eq-hash eq))
> (define (cache my-name)
> (or
> (table-ref test-cache my-name)
> (table-set test-cache my-name 'image)))
>
> (cache (concat "first-" "name"))
> image
>
> if i now type:
> (table-ref test-cache '"first-name")
> ()
> it's returns ().
>
>
> Anyone a idea what is wrong?
>
> Thank you.
>
Hi fuchur,
your hash-table is defined with test 'eq, but strings
are not 'eq, only 'equal
(eq "foo" "foo")
()
(equal "foo" "foo")
t
Thus you need to say
(define test-cache (make-weak-table equal-hash equal))
Note that you need both 'equal-hash' to generate the key,
and 'equal' for comparison. 'eq-hash' uses the address of
the object to generate the key, but two strings of the same
contents nevertheless usually have different addresses in
memory.
Regards,
womble.
---
--
Sawfish ML