YAP 7.1.0
The Predicates that Read Source Files

Detailed Description

Modules

 Directing and Configuring the Compiler
 The YAP system also includes a number of primitives designed to set compiler parameters and to track the state of the compiler.
 
 Conditional Compilation
 Conditional compilation builds on the same principle as term_expansion/2 , goal_expansion/2 and the expansion of grammar rules to compile sections of the source-code conditionally.
 

Class Documentation

◆ load_files/2

class load_files/2

load_files(+_Files_, +_Options_)

Implementation of the consult/1 family Execution is controlled by the following flags:

  • consult(+ Mode)

    This extension controls the type of file to load If Mode is:

    consult, clauses are added to the data-base, unless from the same file; reconsult, clauses are recompiled, db, these are facts that need to be added to the data-base, exo, these are facts with atoms and integers that can be stored in a compact representation (see load_exo/1 )

  • silent(+ Bool)

    If true, load the file without printing a message The specified value is the default for all files loaded as a result of loading the specified files

  • stream(+ Input)

    This SWI-Prolog extension compiles the data from the stream Input If this option is used, Files must be a single atom which is used to identify the source-location of the loaded clauses as well as remove all clauses if the data is re-consulted

    This option is added to allow compiling from non-file locations such as databases, the web, the user (see consult/1 ) or other servers

  • compilation_mode(+ Mode)

    This extension controls how procedures are compiled If Mode is compact clauses are compiled and no source code is stored; if it is source clauses are compiled and source code is stored; if it is assert_all clauses are asserted into the data-base

  • encoding(+ Encoding)

    Character encoding used in consulting files Please (see Encoding) for supported encodings

  • expand(+ Bool)

    If true, run the filenames through expand_file_name/2 and load the returned files Default is false, except for consult/1 which is intended for interactive use

  • if(+ Condition)

    Load the file only if the specified Condition is satisfied The value true the file unconditionally, changed loads the file if it was not loaded before, or has been modified since it was loaded the last time, not_loaded loads the file if it was not loaded before

  • imports(+ ListOrAll)

    If all and the file is a module file, import all public predicates Otherwise import only the named predicates Each predicate is referred to as \<name\>/\<arity\> This option has no effect if the file is not a module file

  • must_be_module(+ Bool)

    If true, raise an error if the file is not a module file Used by use_module/1 and use_module/2

  • qcompile(+ Value)

    SWI-Prolog flag that controls whether loaded files should be also compiled into qly files The default value is obtained from the flag qcompile:

    never, no qly file is generated unless the user calls qsave_file/1 and friends, or sets the qcompile option in load_files/2 ;

    auto, all files are qcompiled

    large, files above 100KB are qcompiled

    part, not supported in YAP

  • autoload(+ Autoload)

SWI-compatible option where if Autoload is true undefined predicates are loaded on first call

  • derived_from(+ File)

    SWI-compatible option to control make/0 Currently not supported

◆ ensure_loaded/1

class ensure_loaded/1

ensure_loaded(+ F)

defined in the ISO standard

When the files specified by F are module files, ensure_loaded/1 loads them if they have note been previously loaded, otherwise advertises the user about the existing name clashes and prompts about importing or not those predicates Predicates which are not public remain invisible

When the files are not module files, ensure_loaded/1 loads them eh if they have not been loaded before, and does nothing otherwise

F must be a list containing the names of the files to load

◆ consult/1

class consult/1

consult(+ F)

Adds the clauses written in file F or in the list of files F to the program

In YAP consult/1 does not remove previous clauses for the procedures defined in other files than F, but since YAP-6.4.3 it will redefine all procedures defined in F

All code in YAP is compiled, and the compiler generates static procedures by default In case you need to manipulate the original code, the expanded version of the original source code is available by calling source/0 or by enabling the source flag

◆ reconsult/1

class reconsult/1

reconsult(+ F )

◆ compile/1

class compile/1

compile(+ F )

Updates the program by replacing the previous definitions for the predicates defined in F It differs from consult/1 in that it only multifile/1 predicates are not reset in a reconsult Instead, consult/1 sees all predicates as multifile

YAP also offers no difference between consult/1 and compile/1 The two are implemented by the same exact code

Example:

?- [file1, -file2, -file3, file4].

will consult file1 file4 and reconsult file2 and file3 That is, it could be written as:

?- consult(file1),
consult(+ F)

◆ load_db/1

class load_db/1

load_db(+ Files)

load_db( +Files )

Load a database of ground facts All facts must take up the same amount of storage, so that a fact $I$ can be accessed at position P[I-1] This representation thus stores the facts as a huge continuous array, the so-called mega clause

See [for] a motivation for this technique YAP implements this optimization by default whenever it loads a large number of facts (see Yap_BuildMegaClause(PredEntry *ap) ) for the details On the other hand, loading the data-base will cause fragmentation because individual facts facts need extra headers ands tails, and because often new atoms will be stored in the Symbol Table, see LookupAtom(const char *atom) The main advantage of load_db/1 is that it allocates the necessary memory only once Just doing this may halve total memory usage in large in-memory database-oriented applications

Note
Implementation

YAP implements load_db/1 as a two-step non-optimised process First, it counts the nmuber of facts and checks their size Second, it allocates and fills the memory The first step of the algorithm is implemented by dbload_get_space(), and the second by dbload_add_facts()

db_files/1 itself is just a call to load_files/2

properties: deterministic

Load files each one containing as single predicare composed of facts with the same size

◆ prolog_load_context/2

class prolog_load_context/2

prolog_load_context(? Key, ? Value)

Obtain information on what is going on in the compilation process The following keys are available:

Full name for the directory where YAP is currently consulting the file

Full name for the file currently being consulted Notice that included filed are ignored

Current source module

Full name for the file currently being read in, which may be consulted, reconsulted, or included

Stream currently being read in

Stream position at the stream currently being read in For SWI compatibility, it is a term of the form '$stream_position'(0,Line,0,0)

SWI-compatible predicate If the last term has been read from a physical file (i.e., not from the file user or a string), unify File with an absolute path to the file and Line with the line-number in the file Please use prolog_load_context/2

SWI-compatible predicate True if File is a loaded Prolog source file

SWI-compatible predicate True if the predicate specified by ModuleAndPred was loaded from file File, where File is an absolute path name (see absolute_file_name/2 )

Definition at line 1 of file consult.yap.