Abstract
Early Prolog implementations, such as those defined by Clocksin and Mellish, operated within a single, flat database namespace. This architecture hindered the development of reusable libraries due to name collisions, redundant memory usage, and the lack of private routines. This paper by Alan Feuer proposes a modular framework using "modules" and "views" to provide scoped execution contexts and efficient library management.
Introduction: The Flat Namespace Problem
In standard Prolog, the database is essentially one giant, flat namespace. This creates significant challenges for library developers:
- Lack of Encapsulation: Helper routines (e.g.,
revzapfor a fastreverse) are exposed to the entire program, risking accidental invocation or name clashes. - Redundant Loading: Multiple libraries depending on a common utility (like a
listlibrary) often cause the utility to be loaded multiple times, wasting memory and increasing search complexity. - Name Overloading: It is difficult to maintain distinct versions of common routines (e.g.,
deletefor sets vs. queues) without interference.
Proposed Modular Architecture
Feuer suggests partitioning the Prolog database into distinct modules. Each routine belongs to exactly one module, providing a natural boundary for code organization.
Private Routines and Scoping
To support encapsulation, the author introduces a mechanism for private routines. By tagging a routine as private (often denoted by a naming convention like $routine), it becomes invisible outside its home module. This ensures that internal implementation details do not leak into the global scope.
As shown in the figure above, routines like revzap can be explicitly marked as PRIVATE, preventing external modules from accessing them directly while allowing other routines within the same module, such as reverse, to utilize them.
Scoped Contexts through Views
The core innovation of the paper is the concept of a view. A view is an ordered sequence of modules, represented internally as a chain of ModuleRef objects. When Prolog attempts to satisfy a goal, it searches through the modules in the current view in a top-down fashion.
The use(X) Directive
Instead of the traditional consult, the use(X) directive is proposed. This command adds a module to the current view. If the module is already in memory, it simply updates the view pointer, effectively solving the "double loading" problem and ensuring shared dependencies are stored only once.
Absolute Referencing
For cases where the search path must be bypassed, the syntax module$routine allows for absolute referencing, enabling a programmer to call a specific implementation regardless of the current view's order.
Key Insights and Results
By treating the search path as a dynamic context, Feuer's system enables a form of logical inheritance. A module can prioritize its own routines, followed by library routines, and finally built-ins.
Qualitative results of this architecture include:
- Namespace Safety: Auxiliary routines are hidden, protecting library integrity.
- Conflict Resolution: Different modules can define routines with the same name (e.g.,
set$deletevsqueue$delete) without collision. - Memory Efficiency: Shared modules are loaded once and referenced multiple times via the
usedirective.
Conclusion
While the proposed system introduces some search overhead by traversing the view list, the organizational and efficiency benefits for large-scale Prolog development are substantial. This framework moved Prolog away from a "global variable" style of programming toward a modern, modular software engineering paradigm.
Summary updated