[m-users.] Suggestion: hash_table should use a hash function instead of a hash predicate

Ted Stock testock at gmail.com
Tue Sep 29 20:28:27 AEST 2020


Hi,

Summary: Because the compiler may lose the inst of a predicate stored in a data structure, perhaps the hash_table data structure should use a function instead of a predicate as it does currently.


Currently, to create a hash table you have to supply a hash_pred predicate.  This is fine, unless you want to use hash tables in a recursive data structure, e.g., a trie.  The problem arises when you try to retrieve the nested data structure from the trie: the hash_table contained in the returned trie should have an inst of hash_table, which includes an inst of hash_pred for the predicate hash_pred.  However, the hash_table.search predicate returns a value with the inst ground, and you seem to lose the inst information attached to the nested hash_table.  

I modified the hash_table module code to use a hash function instead of a hash predicate, and the compiler accepted the change and the error seems to have gone away, presumably because the default mode for functions is retained by the compiler.

I think the fix would be small: switching the module to use hash_func, and adding hash functions for the various types that currently include a hash predicate.

Best,
Ted


More information about the users mailing list