Next: , Up: Implementation-dependent extensions   [Contents]


19.1 Fact tables

Large tables of facts can be compiled using a different algorithm that is more efficient and produces more efficient code.

A declaration of the form

:- pragma fact_table(Name/Arity, FileName).

tells the compiler that the predicate or function with name Name and arity Arity is defined by a set of facts in an external file FileName. Defining large tables of facts in this way allows the compiler to use a more efficient algorithm for compiling them. This algorithm uses less memory than would normally be required to compile the facts so much larger tables are possible.

Each mode is indexed on all its input arguments so the compiler can produce very efficient code using this technique.

In the current implementation, the table of facts is compiled into a separate C file named FileName.c. The compiler will automatically generate the correct dependencies for this file when the command ‘mmake main_module.depend’ is invoked. This ensures that the C file will be compiled to FileName.o and then linked with the other object files when ‘mmake main_module’ is invoked.

The main limitation of the ‘fact_table’ pragma is that in the current implementation, predicates or functions defined as fact tables can only have arguments of types string, int or float.

Another limitation is that the ‘--high-level-code’ back-end does not support ‘pragma fact_table’ for procedures with determinism nondet or multi.