[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Strings in hash tables
Quoting MichaelL@frogware.com:
> Two questions:
>
> * Is this the best way to use strings as keys in a hash table?
Yes, in version 103.X.
Using `equal?'-based tables might be better in 199.X.
> * Isn't this a strange way for this to work, given expectations about
> "dictionary" containers?
Strings are (usually) mutable, and therefore not interned. So that's
why the normal `eq?' hashing doesn't work.
The default for hash tables is not `equal?' because that's somewhat
fragile (e.g., it gets confused by mutations or cyclic structures; I
notice that the documentation fails to mention the those pitfalls).
> I think it's worth explicity mentioning in the docs how to use
> strings as hash table keys just to save some annoyance time.
Good idea.
Matthew