This section describes directives which manipulate attributes of predicate definitions. The functors dynamic/1, multifile/1 and discontiguous/1 are operators of priority 1150 (see op/3), which implies the list of predicates they involve can just be a comma separated list:
:- dynamic foo/0, baz/2.
On SWI-Prolog all these directives are just predicates. This implies they can also be called by a program. Do not rely on this feature if you want to maintain portability to other Prolog implementations.
Due to the representation technique used at most 4 arguments can be indexed. All indexed arguments should be in the first 32 arguments of the predicate. If more than 4 arguments are specified for indexing only the first 4 will be accepted. Arguments above 32 are ignored for indexing.
Indexing as specified by this predicate uses a quick but linear scan. Without explicit specification the system uses an algorithm depending on the structure of the first argument and number of clauses, In particular, for predicates that can be indexed on the first argument and have many clauses, the system will use an automatically resizing hash-table to provide access time independent from the number of clauses.36SWI-Prolog indexing is no longer state-of-the-art. Better schemas for multi-argument as well as indexing inside compound terms are known. We hope to integrate this in future versions. If---for example---one wants to represents sub-types using a fact list `sub_type(Sub, Super)' that should be used both to determine sub- and super types one should declare sub_type/2 as follows:
:- index(sub_type(1, 1)). sub_type(horse, animal). ... ...
Note that this type of indexing makes selecting clauses much faster but remains linear with respect to the number of clauses, while hashing as described with hash/1 provides constant access time. See also hash/1 and term_hash/2.