Mir*_*lov 5 emacs elisp hashtable
我在ielm中评估了以下elisp代码:
(setq foo-hash (make-hash-table))
(puthash "location" "house" foo-hash)
(defun foo-start ()
(interactive)
(message (gethash "location" foo-hash)))
Run Code Online (Sandbox Code Playgroud)
但是,当我跑(foo-start)或(gethash "location" foo-hash)我得到nil回应.进入foo-hashielm回声:#s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8 data ("location" "house"))
这是一个错误还是我做错了什么?
Emacs版本:24.0.95.1
ata*_*lor 11
elisp中的哈希表eql默认用于比较.eql除非它们是同一个对象,否则字符串将不相等.您可能想要使用equal,它比较字符串的内容.用这个创建你的哈希表:
(make-hash-table :test 'equal)
Run Code Online (Sandbox Code Playgroud)