Did you know ... Search Documentation:
init.pl
PublicShow source
Source memberchk(?E, ?List) is semidet[private]
Semantically equivalent to once(member(E,List)). Implemented in C. If List is partial though we need to do the work in Prolog to get the proper constraint behavior. Needs to be defined early as the boot code uses it.
Source dynamic +Spec is det[private]
Source multifile +Spec is det[private]
Source module_transparent +Spec is det[private]
Source discontiguous +Spec is det[private]
Source volatile +Spec is det[private]
Source thread_local +Spec is det[private]
Source noprofile(+Spec) is det[private]
Source public +Spec is det[private]
Source non_terminal(+Spec) is det[private]
Predicate versions of standard directives that set predicate attributes. These predicates bail out with an error on the first failure (typically permission errors).
Source $iso(+Spec) is det[private]
Set the ISO flag. This defines that the predicate cannot be redefined inside a module.
Source $clausable(+Spec) is det[private]
Specify that we can run clause/2 on a predicate, even if it is static. ISO specifies that public also plays this role. in SWI, public means that the predicate can be called, even if we cannot find a reference to it.
Source $hide(+Spec) is det[private]
Specify that the predicate cannot be seen in the debugger.
Source $set_pattr(+Spec, +Module, +From, +Attr)[private]
Set predicate attributes. From is one of pred or directive.
Source $pattr_directive(+Spec, +Module) is det[private]
This implements the directive version of dynamic/1, multifile/1, etc. This version catches and prints errors. If the directive specifies multiple predicates, processing after an error continues with the remaining predicates.
Source $pi_head(?PI, ?Head)[private]
Source $head_name_arity(+Goal, -Name, -Arity)[private]
$head_name_arity(-Goal, +Name, +Arity)[private]
Source $meta_call(:Goal)[private]
Interpreted meta-call implementation. By default, call/1 compiles its argument into a temporary clause. This realises better performance if the (complex) goal does a lot of backtracking because this interpreted version needs to re-interpret the remainder of the goal after backtracking.

This implementation is used by reset/3 because the continuation cannot be captured if it contains a such a compiled temporary clause.

Source call(:Closure, ?A)[private]
Source call(:Closure, ?A1, ?A2)[private]
Source call(:Closure, ?A1, ?A2, ?A3)[private]
Source call(:Closure, ?A1, ?A2, ?A3, ?A4)[private]
Source call(:Closure, ?A1, ?A2, ?A3, ?A4, ?A5)[private]
Source call(:Closure, ?A1, ?A2, ?A3, ?A4, ?A5, ?A6)[private]
Source call(:Closure, ?A1, ?A2, ?A3, ?A4, ?A5, ?A6, ?A7)[private]
Arity 2..8 is demanded by the ISO standard. Higher arities are supported, but handled by the compiler. This implies they are not backed up by predicates and analyzers thus cannot ask for their properties. Analyzers should hard-code handling of call/2..
Source not(:Goal) is semidet[private]
Pre-ISO version of \+/1. Note that some systems define not/1 as a logically more sound version of \+/1.
Source \+ :Goal is semidet[private]
Predicate version that allows for meta-calling.
Source once(:Goal) is semidet[private]
ISO predicate, acting as call((Goal, !)).
Source ignore(:Goal) is det[private]
Call Goal, cut choice-points on success and succeed on failure. intended for calling side-effects and proceed on failure.
Source false[private]
Synonym for fail/0, providing a declarative reading.
Source catch(:Goal, +Catcher, :Recover)[private]
ISO compliant exception handling.
Source prolog_cut_to(+Choice)[private]
Cut all choice points after Choice
Source $ is det[private]
Declare that from now on this predicate succeeds deterministically.
Source $ :Goal is det[private]
Declare that Goal must succeed deterministically.
Source notrace(:Goal) is semidet[private]
Suspend the tracer while running Goal.
Source reset(:Goal, ?Ball, -Continue)[private]
Delimited continuation support.
Source shift(+Ball)[private]
Source shift_for_copy(+Ball)[private]
Shift control back to the enclosing reset/3. The second version assumes the continuation will be saved to be reused in a different context.
Source call_continuation(+Continuation:list)[private]
Call a continuation as created by shift/1. The continuation is a list of '$cont$'(Clause, PC, EnvironmentArg, ...) structures. The predicate '$call_one_tail_body'/1 creates a frame from the continuation and calls this.

Note that we can technically also push the entire continuation onto the environment and call it. Doing it incrementally as below exploits last-call optimization and therefore possible quadratic expansion of the continuation.

Source catch_with_backtrace(:Goal, ?Ball, :Recover)[private]
As catch/3, but tell library(prolog_stack) to record a backtrace in case of an exception.
Source $recover_and_rethrow(:Goal, +Term)
This goal is used to wrap the catch/3 recover handler if the exception is not supposed to be `catchable'. This applies to exceptions of the shape unwind(Term). Note that we cut to ensure that the exception is not delayed forever because the recover handler leaves a choicepoint.
Source call_cleanup(:Goal, :Cleanup)[private]
Source setup_call_cleanup(:Setup, :Goal, :Cleanup)[private]
Source setup_call_catcher_cleanup(:Setup, :Goal, +Catcher, :Cleanup)[private]
Call Cleanup once after Goal is finished (deterministic success, failure, exception or cut). The call to '$call_cleanup' is translated to I_CALLCLEANUP, I_EXITCLEANUP. These instructions rely on the exact stack layout left by these predicates, where the variant is determined by the arity. See also callCleanupHandler() in pl-wam.c.
Source initialization(:Goal, +When)[private]
Register Goal to be executed if a saved state is restored. In addition, the goal is executed depending on When:
now
Execute immediately
after_load
Execute after loading the file in which it appears. This is initialization/1.
restore_state
Do not execute immediately, but only when restoring the state. Not allowed in a sandboxed environment.
prepare_state
Called before saving a state. Can be used to clean the environment (see also volatile/1) or eagerly execute goals that are normally executed lazily.
program
Works as -g goal goals.
main
Starts the application. Only last declaration is used.

Note that all goals are executed when a program is restored.

Source $run_initialization(?File, +Options) is det[private]
Source $run_initialization(?File, +Action, +Options) is det[private]
Run initialization directives for all files if File is unbound, or for a specified file. Note that '$run_initialization'/2 is called from runInitialization() in pl-wic.c for .qlf files. The '$run_initialization'/3 is called with Action set to loaded when called for a QLF file.
Source $clear_source_admin(+File) is det
Removes source adminstration related to File
See also
- Called from destroySourceFile() in pl-proc.c
Source default_module(+Me, -Super) is multi[private]
Is true if `Super' is `Me' or a super (auto import) module of `Me'.
Source $undefined_procedure(+Module, +Name, +Arity, -Action) is det
This predicate is called from C on undefined predicates. First allows the user to take care of it using exception/3. Else try to give a DWIM warning. Otherwise fail. C will print an error message.
Source $loading(+Library)[private]
True if the library is being loaded. Just testing that the predicate is defined is not good enough as the file may be partly loaded. Calling use_module/2 at any time has two drawbacks: it queries the filesystem, causing slowdown and it stops libraries being autoloaded from a saved state where the library is already loaded, but the source may not be accessible.
Source $confirm(Spec) is semidet[private]
Ask the user to confirm a question. Spec is a term as used for print_message/2. It is printed the the query channel. This predicate may be hooked using confirm/2, which must return a boolean.
Source $expand_file_search_path(+Spec, -Expanded, +Cond) is nondet[private]
Source expand_file_search_path(+Spec, -Expanded) is nondet[private]
Expand a search path. The system uses depth-first search upto a specified depth. If this depth is exceeded an exception is raised. TBD: bread-first search?
Source absolute_file_name(+Term, -AbsoluteFile, +Options) is nondet[private]
Translate path-specifier into a full path-name. This predicate originates from Quintus was introduced in SWI-Prolog very early and has re-appeared in SICStus 3.9.0, where they changed argument order and added some options. We addopted the SICStus argument order, but still accept the original argument order for compatibility reasons.
Source user:prolog_file_type(?Extension, ?Type)[multifile]
Define type of file based on the extension. This is used by absolute_file_name/3 and may be used to extend the list of extensions used for some type.

Note that qlf must be last when searching for Prolog files. Otherwise use_module/1 will consider the file as not-loaded because the .qlf file is not the loaded file. Must be fixed elsewhere.

Source $chk_file(+Spec, +Extensions, +Cond, +UseCache, -FullName)[private]
File is a specification of a Prolog source file. Return the full path of the file.
Source $relative_to(+Condition, +Default, -Dir)[private]
Determine the directory to work from. This can be specified explicitely using one or more relative_to(FileOrDir) options or implicitely relative to the working directory or current source-file.
Source $chk_alias_file(+Spec, +Exts, +Cond, +Cache, +CWD, -FullFile) is nondet[private]
Source $file_conditions(+Condition, +Path)[private]
Verify Path satisfies Condition.
Source $list_to_set(+List, -Set) is det[private]
Turn list into a set, keeping the left-most copy of duplicate elements. Copied from library(lists).
Source $compilation_level(-Level) is det[private]
True when Level reflects the nesting in files compiling other files. 0 if no files are being loaded.
Source compiling[private]
Is true if SWI-Prolog is generating a state or qlf file or executes a `call' directive while doing this.
Source $load_msg_level(+Action, +NestingLevel, -StartVerbose, -EndVerbose)[private]
Source $source_term(+From, -Read, -RLayout, -Term, -TLayout, -Stream, +Options) is nondet[private]
Read Prolog terms from the input From. Terms are returned on backtracking. Associated resources (i.e., streams) are closed due to setup_call_cleanup/3.
Arguments:
From- is either a term stream(Id, Stream) or a file specification.
Read- is the raw term as read from the input.
Term- is the term after term-expansion. If a term is expanded into the empty list, this is returned too. This is required to be able to return the raw term in Read
Stream- is the stream from which Read is read
Options- provides additional options:
encoding(Enc)
Encoding used to open From
syntax_errors(+ErrorMode)
process_comments(+Boolean)
term_position(-Pos)
Source $term_in_file(+In, -Read, -RLayout, -Term, -TLayout, -Stream, +Parents, +Options) is multi[private]
True when Term is an expanded term from In. Read is a raw term (before term-expansion). Stream is the actual stream, which starts at In, but may change due to processing included files.
See also
- '$source_term'/8 for details.
Source $repeat_and_read_error_mode(-Mode) is multi[private]
Calls repeat/1 and return the error mode. The implemenation is like this because during part of the boot cycle expand.pl is not yet loaded.
Source $add_encoding(+Enc, +Options0, -Options)[private]
Source $record_included(+Parents, +File, +Path, +Time, -Message) is det[private]
Record that we included File into the head of Parents. This is troublesome when creating a QLF file because this may happen before we opened the QLF file (and we do not yet know how to open the file because we do not yet know whether this is a module file or not).

I think that the only sensible solution is to have a special statement for this, that may appear both inside and outside QLF `parts'.

Source $master_file(+File, -MasterFile)[private]
Find the primary load file from included files.
Source ensure_loaded(+FileOrListOfFiles)[private]
Load specified files, provided they where not loaded before. If the file is a module file import the public predicates into the context module.
Source use_module(+FileOrListOfFiles)[private]
Very similar to ensure_loaded/1, but insists on the loaded file to be a module file. If the file is already imported, but the public predicates are not yet imported into the context module, then do so.
Source use_module(+File, +ImportList)[private]
As use_module/1, but takes only one file argument and imports only the specified predicates rather than all public predicates.
Source reexport(+Files)[private]
As use_module/1, exporting all imported predicates.
Source reexport(+File, +ImportList)[private]
As use_module/1, re-exporting all imported predicates.
Source load_files(:File, +Options)[private]
Common entry for all the consult derivates. File is the raw user specified file specification, possibly tagged with the module.
Source $noload(+Condition, +FullFile, +Options) is semidet[private]
True of FullFile should not be loaded.
Source $qlf_file(+Spec, +PlFile, -LoadFile, -Mode, +Options) is det[private]
Determine how to load the source. LoadFile is the file to be loaded, Mode is how to load it. Mode is one of
compile
Normal source compilation
qcompile
Compile from source, creating a QLF file in the process
qload
Load from QLF file.
stream
Load from a stream. Content can be a source or QLF file.
Arguments:
Spec- is the original search specification
PlFile- is the resolved absolute path to the Prolog file.
Source $qlf_out_of_date(+PlFile, +QlfFile, -Why) is semidet[private]
True if the QlfFile file is out-of-date because of Why. This predicate is the negation such that we can return the reason.
Source $qlf_auto(+PlFile, +QlfFile, +Options) is semidet[private]
True if we create QlfFile using qcompile/2. This is determined by the option qcompile(QlfMode) or, if this is not present, by the prolog_flag qcompile.
Source $load_file(+Spec, +ContextModule, +Options) is det[private]
Load the file Spec into ContextModule controlled by Options. This wrapper deals with two cases before proceeding to the real loader:
Source $resolved_source_path(+File, -FullFile, +Options) is semidet[private]
True when File has already been resolved to an absolute path.
Source $resolve_source_path(+File, -FullFile, +Options) is semidet[private]
Resolve a source file specification to an absolute path. May throw existence and other errors.
Source $translated_source(+Old, +New) is det
Called from loading a QLF state when source files are being renamed.
Source $register_resource_file(+FullFile) is det[private]
If we load a file from a resource we lock it, so we never have to check the modification again.
Source $already_loaded(+File, +FullFile, +Module, +Options) is det[private]
Called if File is already loaded. If this is a module-file, the module must be imported into the context Module. If it is not a module file, it must be reloaded.
bug
- A file may be associated with multiple modules. How do we find the `main export module'? Currently there is no good way to find out which module is associated to the file as a result of the first :- module/2 term.
Source $mt_load_file(+File, +FullFile, +Module, +Options) is det[private]
Deal with multi-threaded loading of files. The thread that wishes to load the thread first will do so, while other threads will wait until the leader finished and than act as if the file is already loaded.

Synchronisation is handled using a message queue that exists while the file is being loaded. This synchronisation relies on the fact that thread_get_message/1 throws an existence_error if the message queue is destroyed. This is hacky. Events or condition variables would have made a cleaner design.

Source $qdo_load_file(+Spec, +FullFile, +ContextModule, +Options) is det[private]
Switch to qcompile mode if requested by the option '$qlf'(+Out)
Source $do_load_file(+Spec, +FullFile, +ContextModule, -Action, +Options) is det[private]
Perform the actual loading.
Source $save_file_scoped_flags(-State) is det[private]
Source $restore_file_scoped_flags(-State) is det[private]
Save/restore flags that are scoped to a compilation unit.
Source $import_from_loaded_module(+LoadedModule, +Module, +Options) is det[private]
Import public predicates from LoadedModule into Module
Source $set_verbose_load(+Options, -Old) is det[private]
Set the verbose_load flag according to Options and unify Old with the old value.
Source $set_sandboxed_load(+Options, -Old) is det[private]
Update the Prolog flag sandboxed_load from Options. Old is unified with the old flag.
Errors
- permission_error(leave, sandbox, -)
Source $update_autoload_level(+Options, -OldLevel)[private]
Update the '$autoload_nesting' and return the old value.
Source $print_message(+Level, +Term) is det[private]
As print_message/2, but deal with the fact that the message system might not yet be loaded.
Source $consult_file(+Path, +Module, -Action, -LoadedIn, +Options)[private]
Called from '$do_load_file'/4 using the goal returned by '$consult_goal'/2. This means that the calling conventions must be kept synchronous with '$qload_file'/6.
Source $save_lex_state(-LexState, +Options) is det[private]
Source $assert_load_context_module(+File, -Module, -Options)[private]
Record the module a file was loaded from (see make/0). The first clause deals with loading from another file. On reload, this clause will be discarded by $start_consult/1. The second clause deals with reload from the toplevel. Here we avoid creating a duplicate dynamic (i.e., not related to a source) clause.
Source $load_ctx_options(+Options, -CtxOptions) is det[private]
Select the load options that determine the load semantics to perform a proper reload. Delete the others.
 $check_load_non_module(+File) is det[private]
Test that a non-module file is not loaded into multiple contexts.
Source $load_file(+Path, +Id, -Module, +Options)[private]
'$load_file'/4 does the actual loading.

state(FirstTerm:boolean, Module:atom, AtEnd:atom, Stop:boolean, Id:atom, Dialect:atom)

Source $compile_term(+Term, +Layout, +SrcId, +Options) is det[private]
Source $compile_term(+Term, +Layout, +SrcId, +SrcLoc, +Options) is det[private]
Distinguish between directives and normal clauses.
Source $set_dialect(+Dialect, +State)[private]
Sets the expected dialect. This is difficult if we are compiling a .qlf file using qcompile/1 because the file is already open, while we are looking for the first term to decide wether this is a module or not. We save the dialect and set it after opening the file or module.

Note that expects_dialect/1 itself may be autoloaded from the library.

Source $reset_dialect(+File, +Class) is det[private]
Load .pl files from the SWI-Prolog distribution always in swi dialect.
Source $module3(+Spec) is det[private]
Handle the 3th argument of a module declartion.
Source $module_name(?Name, +Id, -Module, +Options) is semidet[private]
Determine the module name. There are some cases:
  • Option module(Module) is given. In that case, use this module and if Module is the load context, ignore the module header.
  • The initial name is unbound. Use the base name of the source identifier (normally the file name). Compatibility to Ciao. This might change; I think it is wiser to use the full unique source identifier.
Source $redefine_module(+Module, +File, -Redefine)[private]
Source $module_class(+File, -Class, -Super) is det[private]
Determine the file class and initial module from which File inherits. All boot and library modules as well as the -F script files inherit from system, while all normal user modules inherit from user.
Source $import_list(+TargetModule, +FromModule, +Import, +Reexport) is det[private]
Import from FromModule to TargetModule. Import is one of all, a list of optionally mapped predicate indicators or a term except(Import).
Source $import_all(+Import, +Context, +Source, +Reexport, +Strength)[private]
Source $import_all2(+Imports, +Context, +Source, -Imported, -ImpOps, +Strength)[private]
Source $exported_ops(+Module, -Ops, ?Tail) is det[private]
Ops is a list of op(P,A,N) terms representing the operators exported from Module.
Source $import_ops(+Target, +Source, +Pattern)[private]
Import the operators export from Source into the module table of Target. We only import operators that unify with Pattern.
Source $export_list(+Declarations, +Module, -Ops)[private]
Handle the export list of the module declaration for Module associated to File.
Source $execute_directive(:Goal, +File, +Options) is det[private]
Execute the argument of :- or ?- while loading a file.
Source $valid_directive(:Directive) is det[private]
If the flag sandboxed_load is true, this calls prolog:sandbox_allowed_directive/1. This call can deny execution of the directive by throwing an exception.
Source $add_directive_wic2(+Directive, -Type, +Options) is det[private]
Classify Directive as one of load or call. Add a call directive to the QLF file. load directives continue the compilation into the QLF file.
Source $common_goal_type(+Directive, -Type, +Options) is semidet[private]
True when all subgoals of Directive must be handled using load or call.
Source $store_admin_clause(+Clause, ?Layout, +Owner, +SrcLoc) is det[private]
Store a clause into the database for administrative purposes. This bypasses sanity checking.
Source $store_clause(+Clause, ?Layout, +Owner, +SrcLoc) is det[private]
Store a clause into the database.
Arguments:
Owner- is the file-id that owns the clause
SrcLoc- is the file:line term where the clause originates from.
Source $store_clause(+Term, +Id) is det
This interface is used by PlDoc (and who knows). Kept for to avoid compatibility issues.
Source compile_aux_clauses(+Clauses) is det[private]
Compile clauses given the current source location but do not change the notion of the current procedure such that discontiguous warnings are not issued. The clauses are associated with the current file and therefore wiped out if the file is reloaded.

If the cross-referencer is active, we should not (re-)assert the clauses. Actually, we should make them known to the cross-referencer. How do we do that? Maybe we need a different API, such as in:

expand_term_aux(Goal, NewGoal, Clauses)
To be done
- Deal with source code layout?
Source $stage_file(+Target, -Stage) is det[private]
Source $install_staged_file(+Catcher, +Staged, +Target, +OnError)[private]
Create files using staging, where we first write a temporary file and move it to Target if the file was created successfully. This provides an atomic transition, preventing customers from reading an incomplete file.
Source length(?List, ?N)[private]
Is true when N is the length of List.
Source $is_options(@Term) is semidet[private]
True if Term looks like it provides options.
Source $option(?Opt, +Options) is semidet[private]
Source $option(?Opt, +Options, +Default) is det[private]
Source $select_option(?Opt, +Options, -Rest) is semidet[private]
Select an option from Options.
Arguments:
Rest- is always a map.
Source $merge_options(+New, +Default, -Merged) is det[private]
Add/replace options specified in New.
Arguments:
Merged- is always a map.
Source $options_dict(+Options, --Dict) is det[private]
Translate to an options dict. For possible duplicate keys we keep the first.
Source $exit_code(Code)[private]
Determine the exit code baed on the on_error and on_warning flags. Also used by qsave_toplevel/0.
Source at_halt(:Goal)[private]
Register Goal to be called if the system halts.
To be done
- : get location into the error message
Source cancel_halt(+Reason)[private]
This predicate may be called from at_halt/1 handlers to cancel halting the program. If causes halt/0 to fail rather than terminating the process.
 prolog:heartbeat[multifile]
Called every N inferences of the Prolog flag heartbeat is non-zero.
Source $load_additional_boot_files is det
Called from compileFileList() in pl-wic.c. Gets the files from "-c file ..." and loads them into the module user.