[ ECLiPSe Predicate Database built-in.|Group Index| Full Index]

compile(+File)

Compile specified file or list of files File.

+File
Atom, structure or string, or a list of them.

Description

Compiles the specified Prolog source file or list of source files. The atom or string File must be instantiated to a legitimate specification for an existing file except for the suffix.

The predicate tries to add to it the Prolog suffixes from the list specified in the Prolog flag prolog_suffix and look for an existing and readable file. As soon as a file is found which exists, it is taken as the input file name. The default Prolog suffixes are empty suffix, .sd and .pl. Note that if a Prolog source file and its corresponding dump file exist in the same directory, compile/1 finds first the dump file and so for example editing the source file and then compiling a file without suffix will have no apparent effect.

If File is of the form library(Name), the predicates looks for the file in the directories from the library_path flag.

When File is not in the current directory, ECLiPSe first changes the current directory to that of the file. Consequently, recursive compile/1 calls inside compiled files can use relative pathnames. This makes it possible to compile the program top files from any directory and still use only local file names. At the end of the compilation, the current directory is changed back to the initial one. This has the side effect that all calls to cd/1 in queries in the compiled file are ignored.

Compiling a file which contains a module_interface/1 directive completely redefines an existing module of the same name. Otherwise, static procedures are redefined by those occurring in the compiled file, the clauses of dynamic procedures are appended to the existing ones. To add new procedures to an existing module without erasing the whole module the predicate compile/2 is to be used.

Note that the alternative notation [File1, File2, ... , FileN] may be used instead of compile([File1, File2,... , FileN]).

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
File is not instantiated.
(5) Type error
File is instantiated, but not to an atom or string, or a list of atoms or strings.
(66)
A system predicate is being redefined.
(82)
The module in which the clauses should be compiled is locked.
(130)
The head of a clause is not an atom or a compound term.
(131)
A subgoal in the body of a clause is not an atom or a compound term.
(134)
The clauses of a procedure are not consecutive.
(135)
Trying to redefine a protected procedure.
(137)
A procedure which was previously referenced as built-in or external is now defined as a regular one, or vice versa.
(139)
This event is invoked at the end of each compiled file, by default it prints the compilation time and size of compiled code.
(143)
A query in the compiled file has failed.
(145)
A procedure is being redefined in another file than the original one.
(171)
File does not exist.
(275)
Trying to add delay clauses to a built-in or external procedure.

Examples


Success:
   [hanoi].         % compiles the file hanoi.pl

   [eclipse]: sh('cat file1').
   p:-q(hello).
   yes.
   [eclipse]: sh('cat file2').
   q(X) :- writeln(X).
   yes.
   [eclipse]: compile(user), p.
    p :- writeln(hi).
    user compiled 92 bytes in 0.00 seconds
   hi
   yes.
   [eclipse]: compile([file1, file2]), p.
   /home/lp/user/file1 compiled 32 bytes in 0.02 seconds
   /home/lp/user/file2 compiled 92 bytes in 0.00 seconds
   hello
   yes.


   % example showing use of relative pathnames.
   [eclipse]: sh('ls -FR /home/lp/user/pl').
   a.pl        util/

   /home/lp/user/pl/util:
   b.pl        c.pl

   yes.
   [eclipse]: sh('cat /home/lp/user/pl/a.pl').
   :- compile('util/b').
   p.

   yes.
   [eclipse]: compile('/home/lp/user/pl/a').
   /home/lp/user/pl/util/b.pl compiled 92 bytes in 0.00 seconds
   /home/lp/user/pl/a.pl compiled 28 bytes in 0.00 seconds
   yes.

Error:
   compile(F).            (Error 4).
   compile(file1/1).      (Error 5).
   compile(file).         (Error 171).


See Also

autoload / 2, compile / 2, . / 2, compile_stream / 1, compile_term / 1, dump / 1, lib / 1, set_flag / 2, use_module / 1, dbgcomp / 0, nodbgcomp / 0