2012-04-04 3 views
5

में महत्वपूर्ण नहीं देखता रहा ielm में निम्नलिखित elisp कोड का मूल्यांकन:Emacs: gethash hashtable

(setq foo-hash (make-hash-table)) 

(puthash "location" "house" foo-hash) 

(defun foo-start() 
    (interactive) 
    (message (gethash "location" foo-hash))) 

हालांकि मैं जब चलाने (foo-start) या (gethash "location" foo-hash) मैं केवल nil गूँजती मिलता है। Ielm echoes में foo-hash दर्ज करना: #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8 data ("location" "house"))

क्या यह एक बग है या मैं कुछ गलत कर रहा हूं?

Emacs संस्करण: डिफ़ॉल्ट रूप से तुलना के लिए elisp उपयोग eql में 24.0.95.1

उत्तर

11

हैश तालिकाओं। स्ट्रिंग्स eql के बराबर नहीं होंगे जब तक कि वे एक ही वस्तु न हों। आप शायद equal का उपयोग करना चाहते हैं, जो तारों की सामग्री की तुलना करता है। इसके साथ अपनी हैश तालिका बनाएं:

(make-hash-table :test 'equal)