next up previous contents index
Next: Command Line Arguments Up: The Dynamic Loader and Previous: Changing the Default Search   Contents   Index

Dynamically loading predicates in the interpreter

Modules are usually loaded into an environment when they are consulted (see section 3.7). Specific predicates from a module can also be imported into the run-time environment through the standard predicate import PredList from Module. Here, PredList can either be a Prolog list or a comma list. (The import/1 can also be used as a directive in a source module (see section 3.3).

We provide a sample session for compiling, dynamically loading, and querying a user-defined module named quick_sort. For this example we assume that quick_sort is a file in the current working directory, and contains the definitions of the predicates concat/3 and qsort/2, both of which are exported.


             | ?- compile(quick_sort).
             [Compiling ./quick_sort]
             [quick_sort compiled, cpu time used: 1.439 seconds]

             yes
             | ?- import concat/3, qsort/2 from quick_sort. 

             yes
             | ?- concat([1,3], [2], L), qsort(L, S).

             L = [1,3,2]
             S = [1,2,3]

             yes.

The standard predicate import/1 does not load the module containing the imported predicates, but simply informs the system where it can find the definition of the predicate when (and if) the predicate is called.


next up previous contents index
Next: Command Line Arguments Up: The Dynamic Loader and Previous: Changing the Default Search   Contents   Index
Baoqiu Cui
2000-04-23