I evaluated the following elisp code in ielm:
(setq foo-hash (make-hash-table))
(puthash "location" "house" foo-hash)
(defun foo-start ()
(interactive)
(message (gethash "location" foo-hash)))
However when i run (foo-start)
or (gethash "location" foo-hash)
i get only nil
echoed. Entering just foo-hash
in ielm echoes: #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8 data ("location" "house"))
Is that a bug or i am doing something wrong?
Emacs version: 24.0.95.1
Hash tables in elisp use eql
for comparison by default. Strings won't be equal with eql
unless they're the same object. You probably want to use equal
, which compares the contents of the strings. Create your hash table with this:
(make-hash-table :test 'equal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With