Hi Aleksandar, Aleksandar Sandic <asf...@gmx.de> writes:
>> An equality test on hash tables needs to know how to compare the keys >> and how to compare the values. There's no way to pass those additional >> arguments to 'equal?', so it can't do that job. > It has to compare the values, but not the keys. There's an implicit equality test on keys every time you perform a hash table lookup. By using 'hash-ref' and 'hash-get-handle', you are implicitly using 'equal?' to compare the keys in the hash table with the key that you're asking to look up. Guile's native hash tables are unusual in that they do not internally keep track of which equality test on keys to use. Instead, it is your responsibility to consistently use the functions corresponding to same equality test in all accesses to a given hash table. As the Guile manual states: Like the association list functions, the hash table functions come in several varieties, according to the equality test used for the keys. Plain ‘hash-’ functions use ‘equal?’, ‘hashq-’ functions use ‘eq?’, ‘hashv-’ functions use ‘eqv?’, and the ‘hashx-’ functions use an application supplied test. A single ‘make-hash-table’ creates a hash table suitable for use with any set of functions, but it’s imperative that just one set is then used consistently, or results will be unpredictable. <https://www.gnu.org/software/guile/manual/html_node/Hash-Table-Reference.html> So, your 'hash-table-equal?' predicate implicitly assumes that the hash tables passed to it were populated using 'hash-set!' or 'hash-create-handle!'. If it is applied to a hash table that was populated with the 'hashq-*!', 'hashv-*!', or 'hashx-*!' procedures, then the results will be unpredictable. My 'hash-table=?' predicate makes the same implicit assumption. Mark