[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Strings in hash tables
Surprisingly, this displays "not found":
(let ([h (make-hash-table)])
(hash-table-put! h "some-key" #t)
(if (hash-table-get h "some-key" (lambda () #f) )
(display "found")
(display "not found")))
This displays "found":
(let ([h (make-hash-table)])
(hash-table-put! h (string->symbol "some-key") #t)
(if (hash-table-get h (string->symbol "some-key") (lambda () #f) )
(display "found")
(display "not found")))
Two questions:
* Is this the best way to use strings as keys in a hash table?
* Isn't this a strange way for this to work, given expectations about "dictionary" containers?
At the very least, given that this is different from Python, Ruby, TCL, etc., I think it's worth explicity mentioning in the docs how to use strings as hash table keys just to save some annoyance time.