使用 prolog 进行大型编程
我试图保持我的 Prolog 代码模块化,我想知道是否有人对如何做到这一点有任何建议。我使用简单的consult
来完成此操作,但随着我的文件数量增加并屈服于名称冲突,这变得很麻烦。是否有任何类似于“典型”导入的构造,例如
%-------------------------------------------------------------------- compiler.pl
[ scanner, parser, codegen ] .
%-------------------------------------------------------------------- compile
% compile( S, I ) :- Compiling the source string S gives the list of instructions
% I
compile( S, I ) :- scan( S, T ), parse( T, A ), codegen( A, I ) .
%-------------------------------------------------------------------------------%
在源文件的顶部?如果它是特定于程序的,我使用gprolog
。预先感谢您的任何帮助。
I'm trying to keep my Prolog code modular, and I was wondering if anyone had any advice as to how to do this. The way I was doing this with simple consult
s, but that is getting cumbersome as the number of my files increase and succumbs to name clashes. Is there any construct similar to that of a "typical" import, such as
%-------------------------------------------------------------------- compiler.pl
[ scanner, parser, codegen ] .
%-------------------------------------------------------------------- compile
% compile( S, I ) :- Compiling the source string S gives the list of instructions
% I
compile( S, I ) :- scan( S, T ), parse( T, A ), codegen( A, I ) .
%-------------------------------------------------------------------------------%
at the top of a source file? If it is program specific, I'm using gprolog
. Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GNU-Prolog 没有真正的模块系统,因此您的方法是目前您可以获得的最佳方法。也许 GNU-Prolog 将来可能会添加一个模块系统,但我不会把赌注押在它上面。
最常见的模块系统允许在不同的模块中定义具有相同谓词名称和数量的谓词。从而避免了谓词的名称冲突。原子和函子在模块边界上保持不变。 SICStus、YAP、SWI、Ciao、IF 和 ISO 标准等系统都有这样的系统。
XSB 提供了另一种模块系统 - 称为基于函子。
GNU-Prolog does not have a genuine module system, so your approach is currently the best you can get. Maybe GNU-Prolog might add a module system in the future, but I would not bet a business on it.
The most frequent module system permits to define in different modules predicates with the same predicate name and arity. Thereby name clashes of predicates are avoided. Atoms and functors remain the same over module boundaries. Systems like SICStus, YAP, SWI, Ciao, IF and the ISO standard have such a system.
Another kind of module system is offered by XSB - called functor based.
获取当前的 Logtalk 开发版本,该版本为 GNU Prolog 1.4.0 的稳定版本提供全面支持。您可以通过 Subversion 签出或 Git 克隆来获取它(请参阅 http://logtalk.org/download.html 了解详细信息)。或者私下发邮件给我,我将为您构建一个安装程序。 Logtalk 是专为大规模编程而设计的。您可以使用它来编写可移植应用程序(Logtalk 在九个不同的 Prolog 编译器上按原样运行)。您甚至可以使用它在不包含模块系统的 Prolog 编译器(例如 GNU Prolog)中运行 Prolog 模块代码。 Logtalk 附带了一百多个示例、可移植库、可移植开发人员工具和完整文档。从 Prolog 到 Logtalk 非常容易。编写可移植代码胜过每天移植;-)
Get the current Logtalk development release, which provides full support for the stable release of GNU Prolog 1.4.0. You can get it by doing a Subversion checkout or a Git clone (see http://logtalk.org/download.html for details). Or just mail me privately and I will build an installer for you. Logtalk was designed from the ground up for programming in the large. You can use it to write portable applications (Logtalk runs as-is on nine different Prolog compilers). You can even use it to run Prolog module code in Prolog compilers such as GNU Prolog that don't include a module system. Logtalk comes with more than one hundred examples, portable libraries, portable developer tools, and full documentation. Going from Prolog to Logtalk is quite easy. Writing portable code beats porting every day ;-)
说的假的就是对的。
然而,您可能会考虑 Logtalk,它在多个 Prolog(包括 GNU-Prolog)之上实现了一个模块系统以及一个 OO 系统。
http://logtalk.org/faq.html#general-3
http://logtalk.org/
What false said is right.
However, you might consider Logtalk which implements a module system as well as an OO system on top of several Prologs (GNU-Prolog included).
http://logtalk.org/faq.html#general-3
http://logtalk.org/