Next: , Up: Indexing   [Contents][Index]


9.5.1 Overview

In SICStus Prolog, predicates are indexed on their first arguments. This means that when a predicate is called with an instantiated first argument, a hash table is used to gain fast access to only those clauses having a first argument with the same primary functor as the one in the predicate call. If the first argument is atomic, then only clauses with a matching first argument are accessed. Indexes are maintained automatically by the built-in predicates manipulating the Prolog database (for example, assert/1, retract/1, and compile/1.

Keeping this feature in mind when writing programs can help speed their execution. Some hints for program structuring that will best use the indexing facility are given below. Note that interpreted, e.g. dynamic, predicates as well as compiled predicates are indexed. The programming hints given in this section apply equally to compiled and to interpreted code.


Send feedback on this subject.