next up previous contents index
Next: Ground, Numbervars, Subsumption, Variant Up: Library Utilities Previous: Attributed Variables   Contents   Index


Asserting Dynamic Code

The module consult in directory lib provides several handy library predicates that can assert the contents of a file into XSB's database. The use of these predicates may be necessary when the code needs to be dynamic (so that it is retractable), or when it contains atoms whose length is more than 255 that cannot be handled by the XSB compiler.

load_dyn(+FileName)
consult
Asserts the contents of file FileName into the database. All existing clauses of the predicates in the file that already appear in the database, are retracted, unless there is a multifile/1 declaration for them. Clauses in the file must be in a format that read/1 will process. So, for example, operators are permitted. As usual, clauses of predicates are not retracted if they are compiled instead of dynamically asserted. All predicates are loaded into usermod. Module declarations such as :- export are ignored and a warning is issued.

Dynamically loaded files can be filtered through the XSB preprocessor. To do this, put the following in the source file:

    :- compiler_options([xpp_on]).

Of course, the name compiler_options might seem like a misnomer here (since the file is not being compiled), but it is convenient to use the same directive both for compiling and loading, in case the same source file is used both ways.

ensure_dyn_loaded(+FileName)
consult
Is similar to load_dyn/1 except that it does nothing if the file has previously been loaded and the file has not been changed since. However the file will be reloaded if the index declaration of any predicate in that file has changed to require more indexing, or a larger hash table.

load_dync(+FileName)
consult
Asserts the contents of file FileName into the database. All existing clauses of the predicates in the file that already appear in the database, are retracted unless there is a multifile/1 directive for them. The terms in the file FileName must be in ``canonical'' format; that is, they must not use any operators (or list notation.) This is the format produced by the predicate write_canonical/1. (See cvt_canonical/2 to convert a file from the usual read/1 format to read_canonical format.) As usual, clauses of predicates are not retracted if they are compiled instead of dynamically asserted. All predicates are loaded into usermod. :- export declarations are ignored and a warning is issued.

Notice that this predicate can be used to load files of Datalog facts (since they will be in canonical format). This predicate is significantly faster than load_dyn/1 and should be used when speed is important. A file that is to be dynamically loaded often but not often modified by hand should be loaded with this predicate. Use predicate cvt_canonical/2 (see below) to convert a usual file to a format readable by this predicate.

As with load_dyn/1, the source file can be filtered through the C preprocessor. However, since all clauses in such a file must be in canonical form, the compiler_options/1 directive should look as follows:

     :-(compiler_options('.'(xpp_on,[]))).

ensure_dync_loaded(+FileName)
consult
Is similar to load_dync/1 except that it does nothing if the file has previously been loaded and the file has not been changed since. However the file will be reloaded if the index declaration of any predicate in that file has changed to require more indexing, or a larger hash table.

cvt_canonical(+FileName1,+FileName2)
consult
Converts a file from standard term format to ``canonical'' format. The input file name is FileName1; the converted file is put in FileName2. This predicate can be used to convert a file in standard Prolog format to one loadable by load_dync/1.


next up previous contents index
Next: Ground, Numbervars, Subsumption, Variant Up: Library Utilities Previous: Attributed Variables   Contents   Index
Luis Fernando P. de Castro 2003-06-27