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, .ecl and .pl.
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/1 or module/3 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]).
In addition to the exceptions listed below, any exception can occur during compilation, because general code may be executed in directives (:-/2), file queries (?-/2), macro transformations and inline expansion code.
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).