- Documentation
- Reference manual
- Introduction
- Overview
- Initialising and Managing a Prolog Project
- Built-in Predicates
- SWI-Prolog extensions
- Modules
- Why Use Modules?
- Defining a Module
- Importing Predicates into a Module
- Controlled autoloading for modules
- Defining a meta-predicate
- Overruling Module Boundaries
- Interacting with modules from the top level
- Composing modules from other modules
- Operators and modules
- Dynamic importing using import modules
- Reserved Modules and using the‘user’module
- An alternative import/export interface
- Dynamic Modules
- Transparent predicates: definition and context module
- Module properties
- Compatibility of the Module System
- Tabled execution (SLG resolution)
- Constraint Logic Programming
- CHR: Constraint Handling Rules
- Multithreaded applications
- Coroutining using Prolog engines
- Foreign Language Interface
- Using SWI-Prolog in your browser (WASM)
- Deploying applications
- Packs: community add-ons
- The SWI-Prolog library
- Hackers corner
- Compatibility with other Prolog dialects
- Glossary of Terms
- SWI-Prolog License Conditions and Tools
- Summary
- Bibliography
- Packages
- Reference manual
6 Modules
A Prolog module is a collection of predicates which defines a public interface by means of a set of provided predicates and operators. Prolog modules are defined by an ISO standard. Unfortunately, the standard is considered a failure and, as far as we are aware, not implemented by any concrete Prolog implementation. The SWI-Prolog module system syntax is derived from the Quintus Prolog module system. The Quintus module system has been the starting point for the module systems of a number of mainstream Prolog systems, such as SICStus, Ciao and YAP. The underlying primitives of the SWI-Prolog module system differ from the mentioned systems. These primitives allow for multiple modules in a file, hierarchical modules, emulation of other modules interfaces, etc.
This chapter motivates and describes the SWI-Prolog module system. Novices can start using the module system after reading section 6.2 and section 6.3. The primitives defined in these sections suffice for basic usage until one needs to export predicates that call or manage other predicates dynamically (e.g., use call/1, assert/1, etc.). Such predicates are called meta predicates and are discussed in section 6.5. Section 6.6 to section 6.9 describe more advanced issues. Starting with section 6.10, we discuss more low-level aspects of the SWI-Prolog module system that are used to implement the visible module system, and can be used to build other code reuse mechanisms.