Programming in the large with prolog
Asked Answered
V

3

17

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 consults, 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.

Vision answered 14/7, 2011 at 15:29 Comment(0)
H
9

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 ;-)

Heliolatry answered 15/7, 2011 at 0:30 Comment(0)
C
11

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.

Contrariwise answered 14/7, 2011 at 15:42 Comment(0)
H
9

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 ;-)

Heliolatry answered 15/7, 2011 at 0:30 Comment(0)
K
5

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/

Krystlekrystyna answered 14/7, 2011 at 17:22 Comment(2)
The mentioned predicate based module systems are all very similar be they open source or commercial. Porting from one to the other is relatively simple. That is, you have several possible providers. The Logtalk system is quite different and there is only one source.Contrariwise
Yes, Logtalk is different. But, despite the differences, Logtalk subsumes Prolog modules in most of their functionality and is able to compile Prolog modules as objects. For example, most of the current SWI-Prolog basic library can be compiled and used as objects by only changing the file name extension from .pl to .lgt.Heliolatry

© 2022 - 2024 — McMap. All rights reserved.