## 5.9 Dynamic importing using import modules

Until now we discussed the public module interface that is, at least to some extent, portable between Prolog implementation with a module system that is derived from Quintus Prolog. The remainder of this chapter describes the underlying mechanisms that can be used to emulate other module systems or implement other code-reuse mechanisms.

In addition to built-in predicates, imported predicates and locally defined predicates, SWI-Prolog modules can also call predicates from its import modules. Each module has a (possibly empty) list of import modules. In the default setup, each new module has a single import module, which is `user` for all normal user modules and `system` for all system library modules. Module `user` imports from `system` where all built-in predicates reside. These special modules are described in more detail in section 5.10.

The list of import modules can be manipulated and queried using the following predicates:

set_base_module(:Module)
  Set the default import module of the current module to Module. Typically, Module is one of `user` or `system`.
import_module(+Module, -Import)
  True if Import is defined as an import module for Module. All normal modules only import from `user`, which imports from `system`. The predicates add_import_module/3 and delete_import_module/2 can be used to manipulate the import list.
add_import_module(+Module, +Import, +StartOrEnd)
  If Import is not already an import module for Module, add it to this list at the `start` or `end` depending on StartOrEnd. See also import_module/2 and delete_import_module/2.
delete_import_module(+Module, +Import)
  Delete Import from the list of import modules for Module. Fails silently if Import is not in the list.

One usage scenario of import modules is to define a module that is a copy of another, but where one or more predicates have an alternative definition.