The predicates term_hash/2 and term_hash/4 are typically used to add
indexable additional arguments. For example, if the second argument of a
predicate info/2 is a compound term and you indexing if info is called
as info(-,++)
, i.e., unbound first and ground second argument, you can
do the following:
assert_info(For, Info) :- term_hash(Info, Hash), assert_info(For, Info, Hash). info(For, Info) :- term_hash(Info, Hash), info(For, Info, Hash).
If info/2 is a static predicate, you can use:
term_expansion(info(For,Info), info(For,Info,Hash)) :- term_hash(Info, Hash). info(penguine, flies(false)).
This pattern can also be used to create hashes from multiple arguments to speedup queries that have multiple arguments instantiated, but none of the individual arguments provides a good index.