Programming in the large with prolog
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 ), code开发者_如何转开发gen( A, I ) .
%-------------------------------------------------------------------------------%
at the top of a source file? If it is program specific, I'm using gprolog
. Thanks in advance for any help.
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.
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 ;-)
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/
精彩评论