The ability to compose code in a modular fashion is important to the construction of large programs. In the logic programming setting, it is desirable that such capabilities be realized through logic-based devices. We describe an approach for doing this here. In our scheme a module corresponds to a block of code whose external view is mediated by a signature. Thus, signatures impose a form of hiding that is explained logically via existential quantifications over predicate, function and constant names. Modules interact through the mechanism of accumulation that translates into conjoining the clauses in them while respecting the scopes of existential quantifiers introduced by signatures. We show that this simple device for statically structuring name spaces suffices for realizing features related to code scoping for which the dynamic control of predicate definitions was earlier considered necessary. The module capabilities we present have previously been implemented via the compile-time inlining of accumulated modules. This approach does not support separate compilation. We redress this situation by showing how each distinct module can be compiled separately and inlining can be realized by a later, complementary and equally efficient linking phase.
翻译:模块化组合代码的能力对于构建大型程序至关重要。在逻辑编程环境中,期望通过基于逻辑的机制来实现这种能力。我们在此描述了一种实现该目标的方法。在我们的方案中,模块对应于一块代码,其外部视图由签名中介。因此,签名施加了一种通过谓词、函数和常量名称上的存在量词进行逻辑解释的隐藏形式。模块通过累积机制进行交互,该机制将模块中的子句合取在一起,同时尊重签名所引入的存在量词的作用域。我们证明,这种用于静态组织命名空间的简单机制足以实现代码作用域相关特性,而此前认为这些特性需要通过谓词定义的动态控制来实现。我们提出的模块功能先前已通过编译时内联累积模块的方式实现,但该方法不支持分离编译。我们通过展示如何独立编译每个不同的模块,并通过后续互补且同样高效的链接阶段实现内联,从而解决了这一问题。