2 ms·
Unification & resolution makes this work like a 2-way map. In portable Prolog code, you can only really make the assumption that the first argument is indexed,
by danieldk 13y ago
Unification & resolution makes this work like a 2-way map.
In portable Prolog code, you can only really make the assumption that the first argument is indexed, if it is an atom or a term (in the latter case the functor and arity is used).
In other words, if you have many parent/2 facts
parent(patricia,X).
will be a constant-time lookup, while
parent(X,shelly).
will not be. Another thing to keep in mind is that there can be multiple clauses that unify with a goal.
Real-world story: in the natural language generator that I co-developed, we rewrote every grammar rule with term expansion, such that the attribute-value structure for the syntactic head was the first argument. In this manner, lookups of grammar rules are much faster, since you only have to try to unify with the rules with the corresponding syntactic category.
tl;dr Prolog facts can be used to create mappings. Don't use them as a two-way map without extra precaution if you have a large number of facts.