built-in predicate




Compiles to disk a source file or a list of source files using the default compiler flag values. The Logtalk source file name extension (by default, .lgt) can be omitted. Source file paths can be absolute, relative to the current directory, or use library notation. This predicate can also be used to compile Prolog source files as Logtalk source code. When no recognized Logtalk or Prolog extension is specified, the compiler tries first to append a Logtalk source file extension and then a Prolog source file extension. If that fails, the compiler tries to use the file name as-is. The recognized Logtalk and Prolog file extensions are defined in the backend adapter files.


This predicate does not load into memory the compiled source file. If you want to both compile and load a source file, use instead the logtalk_load/1 built-in predicate.

When this predicate is called from the top-level interpreter, relative source file paths are resolved using the current working directory. When the calls are made from a source file, relative source file paths are resolved using the source file directory.

Note that only the errors related to problems in the predicate argument are listed below. This predicate fails on the first error found during compilation of a source file. In this case, no file with the compiled code is written to disk.

Modes and number of proofs

logtalk_compile(@source_file_name) - zero_or_one
logtalk_compile(@list(source_file_name)) - zero_or_one


File is a variable:
Files is a variable or a list with an element which is a variable:
File, or an element File of the Files list, is neither a variable nor a source file name:
type_error(source_file_name, File)
File, or an element File of the Files list, uses library notation but the library does not exist:
existence_error(library, Library)
File or an element File of the Files list does not exist:
existence_error(file, File)


% compile to disk the "set" source file in the
% current directory:
| ?- logtalk_compile(set).

% compile to disk the "tree" source file in the
% "types" library directory:
| ?- logtalk_load(types(tree)).

% compile to disk the "listp" and "list" source
% files in the current directory:
| ?- logtalk_compile([listp, list]).