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.
翻译:通过逻辑引用,以模块化的方式组合代码,对于构建大型程序非常重要。我们在此描述了一种实现该能力的方法。在我们的方案中,一个模块对应于一块通过签名中介的代码,签名通过谓词、函数和常量名称上的存在量词解释来实现隐藏。因此,签名通过累积的机制,使模块相互交互,该机制将遵守签名引入的存在量词范围,与它们的子句的合并相当于累积。我们表明,这种简单的设备可以通过静态结构名称空间来实现与代码作用域相关的功能,这些功能以前被认为需要用谓词定义的动态控制来实现。我们提出的模块化功能以前已经通过模块的编译时内联实现。但是,这种方法不支持独立编译。我们通过展示如何独立地编译每个不同的模块,并通过后面的补充且同样高效的链接阶段实现内联来纠正这种情况。