2012-04-04 10 views
5

Ho valutato il seguente codice elisp in IeLM:Emacs: gethash non vede chiave nella tabella hash

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

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

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

Tuttavia quando ho eseguito (foo-start) o (gethash "location" foo-hash) ottengo eco solo nil. Inserendo solo foo-hash in ielm echi: #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8 data ("location" "house"))

È un errore o sto facendo qualcosa di sbagliato? Versione

Emacs: 24.0.95.1

risposta

11

tabelle hash in uso elisp eql per il confronto di default. Le stringhe non saranno uguali a eql a meno che non siano lo stesso oggetto. Probabilmente vuoi usare equal, che confronta il contenuto delle stringhe. Crea il tuo hash table con questo:

(make-hash-table :test 'equal) 
Problemi correlati